Closed paresh-navadiya closed 9 years ago
I changed below method and it worked :
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
__strong typeof(weakSelf) strongSelf = weakSelf;
if(strongSelf == nil) return;
if([dataTask.response isKindOfClass:[NSHTTPURLResponse class]]) {
NSHTTPURLResponse *r = (NSHTTPURLResponse *)[dataTask response];
if (r)
{
strongSelf.responseHeaders = [r allHeaderFields];
strongSelf.responseStatus = [r statusCode];
strongSelf.responseStringEncodingName = [r textEncodingName];
strongSelf.responseExpectedContentLength = [r expectedContentLength];
NSArray *responseCookies = [NSHTTPCookie cookiesWithResponseHeaderFields:strongSelf.responseHeaders forURL:dataTask.currentRequest.URL];
for(NSHTTPCookie *cookie in responseCookies) {
//NSLog(@"-- %@", cookie);
[strongSelf addCookie:cookie]; // won't store anything when STHTTPRequestCookiesStorageNoStorage
}
}
else {
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"bad response class: %@", [dataTask.response class]]};
NSError *e = [NSError errorWithDomain:NSStringFromClass([strongSelf class]) code:0 userInfo:userInfo];
strongSelf.errorBlock(e);
[session finishTasksAndInvalidate];
return;
}
}
completionHandler(NSURLSessionResponseAllow);
});
}
Thanks for library :+1:
Sample code where i face issue is given below :