Merge pull request #3205 from dreampiggy/bugfix_session_invalid
Ensure the invalid URLSeesion will receive the cancel callback and does not trigger the any exception from framework
This commit is contained in:
commit
15e16e9e7f
|
@ -140,11 +140,12 @@ static void * SDWebImageDownloaderContext = &SDWebImageDownloaderContext;
|
|||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self.session invalidateAndCancel];
|
||||
self.session = nil;
|
||||
|
||||
[self.downloadQueue cancelAllOperations];
|
||||
[self.config removeObserver:self forKeyPath:NSStringFromSelector(@selector(maxConcurrentDownloads)) context:SDWebImageDownloaderContext];
|
||||
|
||||
// Invalide the URLSession after all operations been cancelled
|
||||
[self.session invalidateAndCancel];
|
||||
self.session = nil;
|
||||
}
|
||||
|
||||
- (void)invalidateSessionAndCancel:(BOOL)cancelPendingOperations {
|
||||
|
|
|
@ -194,6 +194,13 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
|
|||
}
|
||||
}
|
||||
|
||||
if (!session.delegate) {
|
||||
// Session been invalid and has no delegate at all
|
||||
[self callCompletionBlocksWithError:[NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorInvalidDownloadOperation userInfo:@{NSLocalizedDescriptionKey : @"Session delegate is nil and invalid"}]];
|
||||
[self reset];
|
||||
return;
|
||||
}
|
||||
|
||||
self.dataTask = [session dataTaskWithRequest:self.request];
|
||||
self.executing = YES;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue