Ensure all the session delegate completionHandler called. Fix the leak when resp…
…onse error code below iOS 10
Showing
1 changed file
with
30 additions
and
12 deletions
@@ -318,16 +318,22 @@ didReceiveResponse:(NSURLResponse *)response | @@ -318,16 +318,22 @@ didReceiveResponse:(NSURLResponse *)response | ||
318 | 318 | ||
319 | // Identify the operation that runs this task and pass it the delegate method | 319 | // Identify the operation that runs this task and pass it the delegate method |
320 | SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask]; | 320 | SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask]; |
321 | - | ||
322 | - [dataOperation URLSession:session dataTask:dataTask didReceiveResponse:response completionHandler:completionHandler]; | 321 | + if ([dataOperation respondsToSelector:@selector(URLSession:dataTask:didReceiveResponse:completionHandler:)]) { |
322 | + [dataOperation URLSession:session dataTask:dataTask didReceiveResponse:response completionHandler:completionHandler]; | ||
323 | + } else { | ||
324 | + if (completionHandler) { | ||
325 | + completionHandler(NSURLSessionResponseAllow); | ||
326 | + } | ||
327 | + } | ||
323 | } | 328 | } |
324 | 329 | ||
325 | - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data { | 330 | - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data { |
326 | 331 | ||
327 | // Identify the operation that runs this task and pass it the delegate method | 332 | // Identify the operation that runs this task and pass it the delegate method |
328 | SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask]; | 333 | SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask]; |
329 | - | ||
330 | - [dataOperation URLSession:session dataTask:dataTask didReceiveData:data]; | 334 | + if ([dataOperation respondsToSelector:@selector(URLSession:dataTask:didReceiveData:)]) { |
335 | + [dataOperation URLSession:session dataTask:dataTask didReceiveData:data]; | ||
336 | + } | ||
331 | } | 337 | } |
332 | 338 | ||
333 | - (void)URLSession:(NSURLSession *)session | 339 | - (void)URLSession:(NSURLSession *)session |
@@ -337,8 +343,13 @@ didReceiveResponse:(NSURLResponse *)response | @@ -337,8 +343,13 @@ didReceiveResponse:(NSURLResponse *)response | ||
337 | 343 | ||
338 | // Identify the operation that runs this task and pass it the delegate method | 344 | // Identify the operation that runs this task and pass it the delegate method |
339 | SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask]; | 345 | SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask]; |
340 | - | ||
341 | - [dataOperation URLSession:session dataTask:dataTask willCacheResponse:proposedResponse completionHandler:completionHandler]; | 346 | + if ([dataOperation respondsToSelector:@selector(URLSession:dataTask:willCacheResponse:completionHandler:)]) { |
347 | + [dataOperation URLSession:session dataTask:dataTask willCacheResponse:proposedResponse completionHandler:completionHandler]; | ||
348 | + } else { | ||
349 | + if (completionHandler) { | ||
350 | + completionHandler(proposedResponse); | ||
351 | + } | ||
352 | + } | ||
342 | } | 353 | } |
343 | 354 | ||
344 | #pragma mark NSURLSessionTaskDelegate | 355 | #pragma mark NSURLSessionTaskDelegate |
@@ -347,19 +358,21 @@ didReceiveResponse:(NSURLResponse *)response | @@ -347,19 +358,21 @@ didReceiveResponse:(NSURLResponse *)response | ||
347 | 358 | ||
348 | // Identify the operation that runs this task and pass it the delegate method | 359 | // Identify the operation that runs this task and pass it the delegate method |
349 | SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task]; | 360 | SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task]; |
350 | - | ||
351 | - [dataOperation URLSession:session task:task didCompleteWithError:error]; | 361 | + if ([dataOperation respondsToSelector:@selector(URLSession:task:didCompleteWithError:)]) { |
362 | + [dataOperation URLSession:session task:task didCompleteWithError:error]; | ||
363 | + } | ||
352 | } | 364 | } |
353 | 365 | ||
354 | - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLRequest * _Nullable))completionHandler { | 366 | - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLRequest * _Nullable))completionHandler { |
355 | 367 | ||
356 | // Identify the operation that runs this task and pass it the delegate method | 368 | // Identify the operation that runs this task and pass it the delegate method |
357 | SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task]; | 369 | SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task]; |
358 | - | ||
359 | if ([dataOperation respondsToSelector:@selector(URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:)]) { | 370 | if ([dataOperation respondsToSelector:@selector(URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:)]) { |
360 | [dataOperation URLSession:session task:task willPerformHTTPRedirection:response newRequest:request completionHandler:completionHandler]; | 371 | [dataOperation URLSession:session task:task willPerformHTTPRedirection:response newRequest:request completionHandler:completionHandler]; |
361 | } else { | 372 | } else { |
362 | - completionHandler(request); | 373 | + if (completionHandler) { |
374 | + completionHandler(request); | ||
375 | + } | ||
363 | } | 376 | } |
364 | } | 377 | } |
365 | 378 | ||
@@ -367,8 +380,13 @@ didReceiveResponse:(NSURLResponse *)response | @@ -367,8 +380,13 @@ didReceiveResponse:(NSURLResponse *)response | ||
367 | 380 | ||
368 | // Identify the operation that runs this task and pass it the delegate method | 381 | // Identify the operation that runs this task and pass it the delegate method |
369 | SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task]; | 382 | SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task]; |
370 | - | ||
371 | - [dataOperation URLSession:session task:task didReceiveChallenge:challenge completionHandler:completionHandler]; | 383 | + if ([dataOperation respondsToSelector:@selector(URLSession:task:didReceiveChallenge:completionHandler:)]) { |
384 | + [dataOperation URLSession:session task:task didReceiveChallenge:challenge completionHandler:completionHandler]; | ||
385 | + } else { | ||
386 | + if (completionHandler) { | ||
387 | + completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil); | ||
388 | + } | ||
389 | + } | ||
372 | } | 390 | } |
373 | 391 | ||
374 | @end | 392 | @end |
-
Please register or login to post a comment