Ensure the invalid URLSeesion will receive the cancel callback and does not trigger the any exception from framework
This commit is contained in:
parent
3fcf40d12f
commit
d452afdb54
|
@ -140,11 +140,12 @@ static void * SDWebImageDownloaderContext = &SDWebImageDownloaderContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
[self.session invalidateAndCancel];
|
|
||||||
self.session = nil;
|
|
||||||
|
|
||||||
[self.downloadQueue cancelAllOperations];
|
[self.downloadQueue cancelAllOperations];
|
||||||
[self.config removeObserver:self forKeyPath:NSStringFromSelector(@selector(maxConcurrentDownloads)) context:SDWebImageDownloaderContext];
|
[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 {
|
- (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.dataTask = [session dataTaskWithRequest:self.request];
|
||||||
self.executing = YES;
|
self.executing = YES;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue