NSURLConnectionDelegate connection:didReceiveData

2020-03-24 04:02发布

I need some help regarding the NSURLConnectionDelegate method.

- (void)startDownload {
NSString *URLString = [NSString stringWithFormat:appRecord.imageURLString]; 
NSURL *url = [NSURL URLWithString:URLString];   
NSURLRequest *request = [NSURLRequest requestWithURL:url];

imageConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];  
if(imageConnection) {
    activeDownload = [NSMutableData data];
}
}

I am using this method to initiate the NSURLConnection, but the

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

is not calling.. Need Help

Thanks in advance, Shibin

2条回答
我想做一个坏孩纸
2楼-- · 2020-03-24 04:14

Sorry but do you do the start in your code ? I don't see it in your extract. There should be a

 [imageConnection start]

somewhere in your code to trigger the start of the connection and get your delegate called asynchronously.

查看更多
Rolldiameter
3楼-- · 2020-03-24 04:21

No single answer but: 1) Put some NSLogs in to display the URL and then validate that it is generated correctly and does return data

2) Check that you have properly declared that you conform to the NSURLConnectionDelegate protocol in the .h

3) Are you threading or messing with the runloops ? " Messages to the delegate will be sent on the thread that calls this method. By default, for the connection to work correctly the calling thread’s run loop must be operating in the default run loop mode."

查看更多
登录 后发表回答