Ensure all the session delegate completionHandler called. Fix the leak when response error code below iOS 10
This commit is contained in:
parent
a9a123fc74
commit
dd68f2f2d4
|
@ -318,16 +318,22 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
|
|
||||||
// Identify the operation that runs this task and pass it the delegate method
|
// Identify the operation that runs this task and pass it the delegate method
|
||||||
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask];
|
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask];
|
||||||
|
if ([dataOperation respondsToSelector:@selector(URLSession:dataTask:didReceiveResponse:completionHandler:)]) {
|
||||||
[dataOperation URLSession:session dataTask:dataTask didReceiveResponse:response completionHandler:completionHandler];
|
[dataOperation URLSession:session dataTask:dataTask didReceiveResponse:response completionHandler:completionHandler];
|
||||||
|
} else {
|
||||||
|
if (completionHandler) {
|
||||||
|
completionHandler(NSURLSessionResponseAllow);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
|
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
|
||||||
|
|
||||||
// Identify the operation that runs this task and pass it the delegate method
|
// Identify the operation that runs this task and pass it the delegate method
|
||||||
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask];
|
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask];
|
||||||
|
if ([dataOperation respondsToSelector:@selector(URLSession:dataTask:didReceiveData:)]) {
|
||||||
[dataOperation URLSession:session dataTask:dataTask didReceiveData:data];
|
[dataOperation URLSession:session dataTask:dataTask didReceiveData:data];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)URLSession:(NSURLSession *)session
|
- (void)URLSession:(NSURLSession *)session
|
||||||
|
@ -337,8 +343,13 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
|
|
||||||
// Identify the operation that runs this task and pass it the delegate method
|
// Identify the operation that runs this task and pass it the delegate method
|
||||||
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask];
|
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask];
|
||||||
|
if ([dataOperation respondsToSelector:@selector(URLSession:dataTask:willCacheResponse:completionHandler:)]) {
|
||||||
[dataOperation URLSession:session dataTask:dataTask willCacheResponse:proposedResponse completionHandler:completionHandler];
|
[dataOperation URLSession:session dataTask:dataTask willCacheResponse:proposedResponse completionHandler:completionHandler];
|
||||||
|
} else {
|
||||||
|
if (completionHandler) {
|
||||||
|
completionHandler(proposedResponse);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark NSURLSessionTaskDelegate
|
#pragma mark NSURLSessionTaskDelegate
|
||||||
|
@ -347,28 +358,35 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
|
|
||||||
// Identify the operation that runs this task and pass it the delegate method
|
// Identify the operation that runs this task and pass it the delegate method
|
||||||
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task];
|
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task];
|
||||||
|
if ([dataOperation respondsToSelector:@selector(URLSession:task:didCompleteWithError:)]) {
|
||||||
[dataOperation URLSession:session task:task didCompleteWithError:error];
|
[dataOperation URLSession:session task:task didCompleteWithError:error];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLRequest * _Nullable))completionHandler {
|
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLRequest * _Nullable))completionHandler {
|
||||||
|
|
||||||
// Identify the operation that runs this task and pass it the delegate method
|
// Identify the operation that runs this task and pass it the delegate method
|
||||||
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task];
|
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task];
|
||||||
|
|
||||||
if ([dataOperation respondsToSelector:@selector(URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:)]) {
|
if ([dataOperation respondsToSelector:@selector(URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:)]) {
|
||||||
[dataOperation URLSession:session task:task willPerformHTTPRedirection:response newRequest:request completionHandler:completionHandler];
|
[dataOperation URLSession:session task:task willPerformHTTPRedirection:response newRequest:request completionHandler:completionHandler];
|
||||||
} else {
|
} else {
|
||||||
|
if (completionHandler) {
|
||||||
completionHandler(request);
|
completionHandler(request);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
|
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
|
||||||
|
|
||||||
// Identify the operation that runs this task and pass it the delegate method
|
// Identify the operation that runs this task and pass it the delegate method
|
||||||
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task];
|
SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task];
|
||||||
|
if ([dataOperation respondsToSelector:@selector(URLSession:task:didReceiveChallenge:completionHandler:)]) {
|
||||||
[dataOperation URLSession:session task:task didReceiveChallenge:challenge completionHandler:completionHandler];
|
[dataOperation URLSession:session task:task didReceiveChallenge:challenge completionHandler:completionHandler];
|
||||||
|
} else {
|
||||||
|
if (completionHandler) {
|
||||||
|
completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in New Issue