NSURLConnectionDelegate connection:didReceiveData not working

限于喜欢 提交于 2019-12-19 07:39:34

问题


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


回答1:


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."




回答2:


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.



来源:https://stackoverflow.com/questions/2824993/nsurlconnectiondelegate-connectiondidreceivedata-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!