Fix the issue that NSOperation conforms to `SDWebImageOperation` check failed. And fix the SDAsyncBlockOperation cancel logic

This commit is contained in:
DreamPiggy 2020-04-30 18:50:18 +08:00
parent 39370d1af8
commit 4173f9f3c1
4 changed files with 29 additions and 5 deletions

View File

@ -112,6 +112,8 @@
327054D6206CD8B3006EA328 /* SDImageAPNGCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 327054D2206CD8B3006EA328 /* SDImageAPNGCoder.h */; settings = {ATTRIBUTES = (Public, ); }; }; 327054D6206CD8B3006EA328 /* SDImageAPNGCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 327054D2206CD8B3006EA328 /* SDImageAPNGCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
327054DA206CD8B3006EA328 /* SDImageAPNGCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 327054D3206CD8B3006EA328 /* SDImageAPNGCoder.m */; }; 327054DA206CD8B3006EA328 /* SDImageAPNGCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 327054D3206CD8B3006EA328 /* SDImageAPNGCoder.m */; };
327054DC206CD8B3006EA328 /* SDImageAPNGCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 327054D3206CD8B3006EA328 /* SDImageAPNGCoder.m */; }; 327054DC206CD8B3006EA328 /* SDImageAPNGCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 327054D3206CD8B3006EA328 /* SDImageAPNGCoder.m */; };
327F2E83245AE1650075F846 /* SDWebImageOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 327F2E82245AE1650075F846 /* SDWebImageOperation.m */; };
327F2E84245AE1650075F846 /* SDWebImageOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 327F2E82245AE1650075F846 /* SDWebImageOperation.m */; };
328BB69E2081FED200760D6C /* SDWebImageCacheKeyFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 328BB69A2081FED200760D6C /* SDWebImageCacheKeyFilter.h */; settings = {ATTRIBUTES = (Public, ); }; }; 328BB69E2081FED200760D6C /* SDWebImageCacheKeyFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 328BB69A2081FED200760D6C /* SDWebImageCacheKeyFilter.h */; settings = {ATTRIBUTES = (Public, ); }; };
328BB6A22081FED200760D6C /* SDWebImageCacheKeyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 328BB69B2081FED200760D6C /* SDWebImageCacheKeyFilter.m */; }; 328BB6A22081FED200760D6C /* SDWebImageCacheKeyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 328BB69B2081FED200760D6C /* SDWebImageCacheKeyFilter.m */; };
328BB6A42081FED200760D6C /* SDWebImageCacheKeyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 328BB69B2081FED200760D6C /* SDWebImageCacheKeyFilter.m */; }; 328BB6A42081FED200760D6C /* SDWebImageCacheKeyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 328BB69B2081FED200760D6C /* SDWebImageCacheKeyFilter.m */; };
@ -437,6 +439,7 @@
326E2F32236F1D58006F847F /* SDDeviceHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDDeviceHelper.m; sourceTree = "<group>"; }; 326E2F32236F1D58006F847F /* SDDeviceHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDDeviceHelper.m; sourceTree = "<group>"; };
327054D2206CD8B3006EA328 /* SDImageAPNGCoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDImageAPNGCoder.h; path = Core/SDImageAPNGCoder.h; sourceTree = "<group>"; }; 327054D2206CD8B3006EA328 /* SDImageAPNGCoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDImageAPNGCoder.h; path = Core/SDImageAPNGCoder.h; sourceTree = "<group>"; };
327054D3206CD8B3006EA328 /* SDImageAPNGCoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDImageAPNGCoder.m; path = Core/SDImageAPNGCoder.m; sourceTree = "<group>"; }; 327054D3206CD8B3006EA328 /* SDImageAPNGCoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDImageAPNGCoder.m; path = Core/SDImageAPNGCoder.m; sourceTree = "<group>"; };
327F2E82245AE1650075F846 /* SDWebImageOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SDWebImageOperation.m; path = Core/SDWebImageOperation.m; sourceTree = "<group>"; };
328BB69A2081FED200760D6C /* SDWebImageCacheKeyFilter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SDWebImageCacheKeyFilter.h; path = Core/SDWebImageCacheKeyFilter.h; sourceTree = "<group>"; }; 328BB69A2081FED200760D6C /* SDWebImageCacheKeyFilter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SDWebImageCacheKeyFilter.h; path = Core/SDWebImageCacheKeyFilter.h; sourceTree = "<group>"; };
328BB69B2081FED200760D6C /* SDWebImageCacheKeyFilter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SDWebImageCacheKeyFilter.m; path = Core/SDWebImageCacheKeyFilter.m; sourceTree = "<group>"; }; 328BB69B2081FED200760D6C /* SDWebImageCacheKeyFilter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SDWebImageCacheKeyFilter.m; path = Core/SDWebImageCacheKeyFilter.m; sourceTree = "<group>"; };
328BB6A82081FEE500760D6C /* SDWebImageCacheSerializer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SDWebImageCacheSerializer.h; path = Core/SDWebImageCacheSerializer.h; sourceTree = "<group>"; }; 328BB6A82081FEE500760D6C /* SDWebImageCacheSerializer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SDWebImageCacheSerializer.h; path = Core/SDWebImageCacheSerializer.h; sourceTree = "<group>"; };
@ -846,6 +849,7 @@
320CAE132086F50500CFFC80 /* SDWebImageError.h */, 320CAE132086F50500CFFC80 /* SDWebImageError.h */,
320CAE142086F50500CFFC80 /* SDWebImageError.m */, 320CAE142086F50500CFFC80 /* SDWebImageError.m */,
530E49E71646388E002868E7 /* SDWebImageOperation.h */, 530E49E71646388E002868E7 /* SDWebImageOperation.h */,
327F2E82245AE1650075F846 /* SDWebImageOperation.m */,
324DF4B2200A14DC008A84CC /* SDWebImageDefine.h */, 324DF4B2200A14DC008A84CC /* SDWebImageDefine.h */,
324DF4B3200A14DC008A84CC /* SDWebImageDefine.m */, 324DF4B3200A14DC008A84CC /* SDWebImageDefine.m */,
325312C6200F09910046BF1E /* SDWebImageTransition.h */, 325312C6200F09910046BF1E /* SDWebImageTransition.h */,
@ -1196,6 +1200,7 @@
4A2CAE201AB4BB6C00B6BC39 /* SDImageCache.m in Sources */, 4A2CAE201AB4BB6C00B6BC39 /* SDImageCache.m in Sources */,
4369C2801D9807EC007E863A /* UIView+WebCache.m in Sources */, 4369C2801D9807EC007E863A /* UIView+WebCache.m in Sources */,
329A18611FFF5DFD008C9A2F /* UIImage+Metadata.m in Sources */, 329A18611FFF5DFD008C9A2F /* UIImage+Metadata.m in Sources */,
327F2E84245AE1650075F846 /* SDWebImageOperation.m in Sources */,
328BB6B22081FEE500760D6C /* SDWebImageCacheSerializer.m in Sources */, 328BB6B22081FEE500760D6C /* SDWebImageCacheSerializer.m in Sources */,
325C4611223394D8004CAE11 /* SDImageCachesManagerOperation.m in Sources */, 325C4611223394D8004CAE11 /* SDImageCachesManagerOperation.m in Sources */,
); );
@ -1270,6 +1275,7 @@
ABBE71A818C43B4D00B75E91 /* UIImageView+HighlightedWebCache.m in Sources */, ABBE71A818C43B4D00B75E91 /* UIImageView+HighlightedWebCache.m in Sources */,
4369C27E1D9807EC007E863A /* UIView+WebCache.m in Sources */, 4369C27E1D9807EC007E863A /* UIView+WebCache.m in Sources */,
329A185F1FFF5DFD008C9A2F /* UIImage+Metadata.m in Sources */, 329A185F1FFF5DFD008C9A2F /* UIImage+Metadata.m in Sources */,
327F2E83245AE1650075F846 /* SDWebImageOperation.m in Sources */,
328BB6B02081FEE500760D6C /* SDWebImageCacheSerializer.m in Sources */, 328BB6B02081FEE500760D6C /* SDWebImageCacheSerializer.m in Sources */,
325C4610223394D8004CAE11 /* SDImageCachesManagerOperation.m in Sources */, 325C4610223394D8004CAE11 /* SDImageCachesManagerOperation.m in Sources */,
); );

View File

@ -0,0 +1,14 @@
/*
* This file is part of the SDWebImage package.
* (c) Olivier Poitrey <rs@dailymotion.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
#import "SDWebImageOperation.h"
/// NSOperation conform to `SDWebImageOperation`.
@implementation NSOperation (SDWebImageOperation)
@end

View File

@ -266,16 +266,18 @@
@synchronized (self) { @synchronized (self) {
[self.prefetchOperations compact]; [self.prefetchOperations compact];
for (id operation in self.prefetchOperations) { for (id operation in self.prefetchOperations) {
if ([operation conformsToProtocol:@protocol(SDWebImageOperation)]) { id<SDWebImageOperation> strongOperation = operation;
[operation cancel]; if (strongOperation) {
[strongOperation cancel];
} }
} }
self.prefetchOperations.count = 0; self.prefetchOperations.count = 0;
[self.loadOperations compact]; [self.loadOperations compact];
for (id operation in self.loadOperations) { for (id operation in self.loadOperations) {
if ([operation conformsToProtocol:@protocol(SDWebImageOperation)]) { id<SDWebImageOperation> strongOperation = operation;
[operation cancel]; if (strongOperation) {
[strongOperation cancel];
} }
} }
self.loadOperations.count = 0; self.loadOperations.count = 0;

View File

@ -52,7 +52,9 @@
- (void)cancel { - (void)cancel {
[super cancel]; [super cancel];
[self complete]; if (self.isExecuting) {
[self complete];
}
} }
- (void)complete { - (void)complete {