I have the below implementation of NSURLSession
.
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
self.session = [NSURLSession sessionWithConfiguration:configuration
delegate:self
delegateQueue: nil];
NSURLSessionDataTask *task = [self.session dataTaskWithRequest:request];
[task resume];
while(!finished) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:100000]];
}
and i have implemented the below delegate methds:
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)aresponse
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didCompleteWithError:(NSError *)error
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition,
NSURLCredential *credential))completionHandler
the "finished" variable for while loop above is set to 1 when didCompleteWithError
delegate is received when indicates that there is some issue like network down, etc...
When network is down, i don't get didCompleteWithErrorcallback
, hence the while loop does not exit even though 10sec timeout has been specified and my app crashes giving Memory warning.
I do properly receive didReceiveData, didReceiveResponse callback in all scenarious .have not checked didReceiveChallenge callback though as it requires HTTPs setup here.
so , i have following questions to ask , if you can help me :
1)Why is didCompleteWithError
callback not received when network is down?
2)Considering no network issues ,is didCompleteWithError
callback received on successful completion of task ?If no, what callback would indicate the completion of task , like connectionDidFinishLoading
when using NSURLConnection
?
I have used cachepolicy in the request parameter while starting task. Is it because of this that didcompletewitherror is not called n instead caching delegate should be implemented??
Guys, Please help. I am stuck.
Thankyou