Add `SDWebImageLoader` protocol for custom image loader. Also introduce the `SDWebImageLoadersManager` to manage multiple loaders with priority
This commit is contained in:
parent
5426a720f7
commit
57db312cc5
|
@ -56,8 +56,10 @@
|
|||
|
||||
// HTTP NTLM auth example
|
||||
// Add your NTLM image url to the array below and replace the credentials
|
||||
[SDWebImageManager sharedManager].imageDownloader.config.username = @"httpwatch";
|
||||
[SDWebImageManager sharedManager].imageDownloader.config.password = @"httpwatch01";
|
||||
[SDWebImageDownloader sharedDownloader].config.username = @"httpwatch";
|
||||
[SDWebImageDownloader sharedDownloader].config.password = @"httpwatch01";
|
||||
[[SDWebImageDownloader sharedDownloader] setValue:@"SDWebImage Demo" forHTTPHeaderField:@"AppName"];
|
||||
[SDWebImageDownloader sharedDownloader].config.executionOrder = SDWebImageDownloaderLIFOExecutionOrder;
|
||||
|
||||
self.objects = [NSMutableArray arrayWithObjects:
|
||||
@"http://www.httpwatch.com/httpgallery/authentication/authenticatedimage/default.aspx?0.35786508303135633", // requires HTTP auth, used to demo the NTLM auth
|
||||
|
@ -78,8 +80,6 @@
|
|||
}
|
||||
|
||||
}
|
||||
[SDWebImageManager.sharedManager.imageDownloader setValue:@"SDWebImage Demo" forHTTPHeaderField:@"AppName"];
|
||||
SDWebImageManager.sharedManager.imageDownloader.config.executionOrder = SDWebImageDownloaderLIFOExecutionOrder;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,30 @@
|
|||
320CAE1E2086F50500CFFC80 /* SDWebImageError.m in Sources */ = {isa = PBXBuildFile; fileRef = 320CAE142086F50500CFFC80 /* SDWebImageError.m */; };
|
||||
320CAE1F2086F50500CFFC80 /* SDWebImageError.m in Sources */ = {isa = PBXBuildFile; fileRef = 320CAE142086F50500CFFC80 /* SDWebImageError.m */; };
|
||||
320CAE202086F50500CFFC80 /* SDWebImageError.m in Sources */ = {isa = PBXBuildFile; fileRef = 320CAE142086F50500CFFC80 /* SDWebImageError.m */; };
|
||||
321B37812083290E00C0EA77 /* SDWebImageLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 321B377D2083290D00C0EA77 /* SDWebImageLoader.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
321B37822083290E00C0EA77 /* SDWebImageLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 321B377D2083290D00C0EA77 /* SDWebImageLoader.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
321B37832083290E00C0EA77 /* SDWebImageLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 321B377D2083290D00C0EA77 /* SDWebImageLoader.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
321B37842083290E00C0EA77 /* SDWebImageLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 321B377D2083290D00C0EA77 /* SDWebImageLoader.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
321B37852083290E00C0EA77 /* SDWebImageLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 321B377D2083290D00C0EA77 /* SDWebImageLoader.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
321B37862083290E00C0EA77 /* SDWebImageLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 321B377D2083290D00C0EA77 /* SDWebImageLoader.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
321B37872083290E00C0EA77 /* SDWebImageLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 321B377E2083290D00C0EA77 /* SDWebImageLoader.m */; };
|
||||
321B37882083290E00C0EA77 /* SDWebImageLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 321B377E2083290D00C0EA77 /* SDWebImageLoader.m */; };
|
||||
321B37892083290E00C0EA77 /* SDWebImageLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 321B377E2083290D00C0EA77 /* SDWebImageLoader.m */; };
|
||||
321B378A2083290E00C0EA77 /* SDWebImageLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 321B377E2083290D00C0EA77 /* SDWebImageLoader.m */; };
|
||||
321B378B2083290E00C0EA77 /* SDWebImageLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 321B377E2083290D00C0EA77 /* SDWebImageLoader.m */; };
|
||||
321B378C2083290E00C0EA77 /* SDWebImageLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 321B377E2083290D00C0EA77 /* SDWebImageLoader.m */; };
|
||||
321B378D2083290E00C0EA77 /* SDWebImageLoadersManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 321B377F2083290E00C0EA77 /* SDWebImageLoadersManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
321B378E2083290E00C0EA77 /* SDWebImageLoadersManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 321B377F2083290E00C0EA77 /* SDWebImageLoadersManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
321B378F2083290E00C0EA77 /* SDWebImageLoadersManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 321B377F2083290E00C0EA77 /* SDWebImageLoadersManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
321B37902083290E00C0EA77 /* SDWebImageLoadersManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 321B377F2083290E00C0EA77 /* SDWebImageLoadersManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
321B37912083290E00C0EA77 /* SDWebImageLoadersManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 321B377F2083290E00C0EA77 /* SDWebImageLoadersManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
321B37922083290E00C0EA77 /* SDWebImageLoadersManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 321B377F2083290E00C0EA77 /* SDWebImageLoadersManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
321B37932083290E00C0EA77 /* SDWebImageLoadersManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 321B37802083290E00C0EA77 /* SDWebImageLoadersManager.m */; };
|
||||
321B37942083290E00C0EA77 /* SDWebImageLoadersManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 321B37802083290E00C0EA77 /* SDWebImageLoadersManager.m */; };
|
||||
321B37952083290E00C0EA77 /* SDWebImageLoadersManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 321B37802083290E00C0EA77 /* SDWebImageLoadersManager.m */; };
|
||||
321B37962083290E00C0EA77 /* SDWebImageLoadersManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 321B37802083290E00C0EA77 /* SDWebImageLoadersManager.m */; };
|
||||
321B37972083290E00C0EA77 /* SDWebImageLoadersManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 321B37802083290E00C0EA77 /* SDWebImageLoadersManager.m */; };
|
||||
321B37982083290E00C0EA77 /* SDWebImageLoadersManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 321B37802083290E00C0EA77 /* SDWebImageLoadersManager.m */; };
|
||||
321DB3612011D4D70015D2CB /* NSButton+WebCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 321DB35F2011D4D60015D2CB /* NSButton+WebCache.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
321DB3622011D4D70015D2CB /* NSButton+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 321DB3602011D4D60015D2CB /* NSButton+WebCache.m */; };
|
||||
321E60861F38E8C800405457 /* SDWebImageCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 321E60841F38E8C800405457 /* SDWebImageCoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
|
@ -1519,6 +1543,10 @@
|
|||
320224BA203979BA00E9F285 /* SDAnimatedImageRep.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDAnimatedImageRep.m; sourceTree = "<group>"; };
|
||||
320CAE132086F50500CFFC80 /* SDWebImageError.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDWebImageError.h; sourceTree = "<group>"; };
|
||||
320CAE142086F50500CFFC80 /* SDWebImageError.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDWebImageError.m; sourceTree = "<group>"; };
|
||||
321B377D2083290D00C0EA77 /* SDWebImageLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageLoader.h; sourceTree = "<group>"; };
|
||||
321B377E2083290D00C0EA77 /* SDWebImageLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageLoader.m; sourceTree = "<group>"; };
|
||||
321B377F2083290E00C0EA77 /* SDWebImageLoadersManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageLoadersManager.h; sourceTree = "<group>"; };
|
||||
321B37802083290E00C0EA77 /* SDWebImageLoadersManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageLoadersManager.m; sourceTree = "<group>"; };
|
||||
321DB35F2011D4D60015D2CB /* NSButton+WebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSButton+WebCache.h"; path = "SDWebImage/NSButton+WebCache.h"; sourceTree = "<group>"; };
|
||||
321DB3602011D4D60015D2CB /* NSButton+WebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSButton+WebCache.m"; path = "SDWebImage/NSButton+WebCache.m"; sourceTree = "<group>"; };
|
||||
321E60841F38E8C800405457 /* SDWebImageCoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageCoder.h; sourceTree = "<group>"; };
|
||||
|
@ -2137,6 +2165,10 @@
|
|||
32B9B536206ED4230026769D /* SDWebImageDownloaderConfig.m */,
|
||||
32F21B4F20788D8C0036B1D5 /* SDWebImageDownloaderRequestModifier.h */,
|
||||
32F21B5020788D8C0036B1D5 /* SDWebImageDownloaderRequestModifier.m */,
|
||||
321B377D2083290D00C0EA77 /* SDWebImageLoader.h */,
|
||||
321B377E2083290D00C0EA77 /* SDWebImageLoader.m */,
|
||||
321B377F2083290E00C0EA77 /* SDWebImageLoadersManager.h */,
|
||||
321B37802083290E00C0EA77 /* SDWebImageLoadersManager.m */,
|
||||
);
|
||||
name = Downloader;
|
||||
sourceTree = "<group>";
|
||||
|
@ -2346,6 +2378,7 @@
|
|||
32B9B53A206ED4230026769D /* SDWebImageDownloaderConfig.h in Headers */,
|
||||
328BB6AD2081FEE500760D6C /* SDWebImageCacheSerializer.h in Headers */,
|
||||
80377C4A1F2F666300F89830 /* bit_writer_utils.h in Headers */,
|
||||
321B37902083290E00C0EA77 /* SDWebImageLoadersManager.h in Headers */,
|
||||
4397D2F81D0DF44200BB2784 /* MKAnnotationView+WebCache.h in Headers */,
|
||||
323F8BE71F38EF770092B609 /* vp8li_enc.h in Headers */,
|
||||
329A185C1FFF5DFD008C9A2F /* UIImage+WebCache.h in Headers */,
|
||||
|
@ -2389,6 +2422,7 @@
|
|||
328BB6D02082581100760D6C /* SDMemoryCache.h in Headers */,
|
||||
321E60891F38E8C800405457 /* SDWebImageCoder.h in Headers */,
|
||||
00733A721BC4880E00A5A117 /* UIView+WebCacheOperation.h in Headers */,
|
||||
321B37842083290E00C0EA77 /* SDWebImageLoader.h in Headers */,
|
||||
80377C481F2F666300F89830 /* bit_reader_utils.h in Headers */,
|
||||
80377C511F2F666300F89830 /* huffman_encode_utils.h in Headers */,
|
||||
32484778201775F600AF9E5A /* SDAnimatedImage.h in Headers */,
|
||||
|
@ -2466,6 +2500,7 @@
|
|||
4314D16F1D0E0E3B004B36C9 /* NSData+ImageContentType.h in Headers */,
|
||||
80377C121F2F666300F89830 /* bit_reader_inl_utils.h in Headers */,
|
||||
4314D1701D0E0E3B004B36C9 /* mux.h in Headers */,
|
||||
321B378E2083290E00C0EA77 /* SDWebImageLoadersManager.h in Headers */,
|
||||
321E60871F38E8C800405457 /* SDWebImageCoder.h in Headers */,
|
||||
80377EA21F2F66D400F89830 /* vp8i_dec.h in Headers */,
|
||||
320CAE162086F50500CFFC80 /* SDWebImageError.h in Headers */,
|
||||
|
@ -2474,6 +2509,7 @@
|
|||
80377C211F2F666300F89830 /* quant_levels_dec_utils.h in Headers */,
|
||||
4314D1721D0E0E3B004B36C9 /* SDWebImageCompat.h in Headers */,
|
||||
32484776201775F600AF9E5A /* SDAnimatedImage.h in Headers */,
|
||||
321B37822083290E00C0EA77 /* SDWebImageLoader.h in Headers */,
|
||||
80377C251F2F666300F89830 /* random_utils.h in Headers */,
|
||||
80377D4F1F2F66A700F89830 /* lossless.h in Headers */,
|
||||
80377D511F2F66A700F89830 /* msa_macro.h in Headers */,
|
||||
|
@ -2528,6 +2564,7 @@
|
|||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
321B37912083290E00C0EA77 /* SDWebImageLoadersManager.h in Headers */,
|
||||
80377C791F2F666400F89830 /* utils.h in Headers */,
|
||||
328BB6A02081FED200760D6C /* SDWebImageCacheKeyFilter.h in Headers */,
|
||||
323F8B721F38EF770092B609 /* delta_palettization_enc.h in Headers */,
|
||||
|
@ -2540,6 +2577,7 @@
|
|||
321E608A1F38E8C800405457 /* SDWebImageCoder.h in Headers */,
|
||||
32484767201775F600AF9E5A /* SDAnimatedImageView+WebCache.h in Headers */,
|
||||
80377C601F2F666400F89830 /* bit_reader_inl_utils.h in Headers */,
|
||||
321B37852083290E00C0EA77 /* SDWebImageLoader.h in Headers */,
|
||||
329A185D1FFF5DFD008C9A2F /* UIImage+WebCache.h in Headers */,
|
||||
431BB6DC1D06D2C1006A3455 /* UIButton+WebCache.h in Headers */,
|
||||
431BB6E11D06D2C1006A3455 /* SDWebImage.h in Headers */,
|
||||
|
@ -2634,6 +2672,7 @@
|
|||
32B9B53C206ED4230026769D /* SDWebImageDownloaderConfig.h in Headers */,
|
||||
328BB6AF2081FEE500760D6C /* SDWebImageCacheSerializer.h in Headers */,
|
||||
4397D2BA1D0DDD8C00BB2784 /* demux.h in Headers */,
|
||||
321B37922083290E00C0EA77 /* SDWebImageLoadersManager.h in Headers */,
|
||||
80377C8F1F2F666400F89830 /* rescaler_utils.h in Headers */,
|
||||
4397D2BD1D0DDD8C00BB2784 /* types.h in Headers */,
|
||||
4397D2C01D0DDD8C00BB2784 /* SDWebImage.h in Headers */,
|
||||
|
@ -2677,6 +2716,7 @@
|
|||
328BB6D22082581100760D6C /* SDMemoryCache.h in Headers */,
|
||||
323F8BDD1F38EF770092B609 /* vp8i_enc.h in Headers */,
|
||||
323F8B671F38EF770092B609 /* cost_enc.h in Headers */,
|
||||
321B37862083290E00C0EA77 /* SDWebImageLoader.h in Headers */,
|
||||
80377EE11F2F66D500F89830 /* vp8_dec.h in Headers */,
|
||||
80377EE41F2F66D500F89830 /* vp8li_dec.h in Headers */,
|
||||
80377C931F2F666400F89830 /* utils.h in Headers */,
|
||||
|
@ -2733,6 +2773,7 @@
|
|||
32B9B539206ED4230026769D /* SDWebImageDownloaderConfig.h in Headers */,
|
||||
328BB6AC2081FEE500760D6C /* SDWebImageCacheSerializer.h in Headers */,
|
||||
80377C301F2F666300F89830 /* bit_writer_utils.h in Headers */,
|
||||
321B378F2083290E00C0EA77 /* SDWebImageLoadersManager.h in Headers */,
|
||||
431739541CDFC8B70008FEB9 /* types.h in Headers */,
|
||||
323F8BE61F38EF770092B609 /* vp8li_enc.h in Headers */,
|
||||
329A185B1FFF5DFD008C9A2F /* UIImage+WebCache.h in Headers */,
|
||||
|
@ -2776,6 +2817,7 @@
|
|||
328BB6CF2082581100760D6C /* SDMemoryCache.h in Headers */,
|
||||
321E60881F38E8C800405457 /* SDWebImageCoder.h in Headers */,
|
||||
4A2CAE371AB4BB7500B6BC39 /* UIView+WebCacheOperation.h in Headers */,
|
||||
321B37832083290E00C0EA77 /* SDWebImageLoader.h in Headers */,
|
||||
80377C2E1F2F666300F89830 /* bit_reader_utils.h in Headers */,
|
||||
80377C371F2F666300F89830 /* huffman_encode_utils.h in Headers */,
|
||||
32484777201775F600AF9E5A /* SDAnimatedImage.h in Headers */,
|
||||
|
@ -2868,6 +2910,7 @@
|
|||
321E60BE1F38E91700405457 /* UIImage+ForceDecode.h in Headers */,
|
||||
5376131E155AD0D5005750A4 /* SDWebImagePrefetcher.h in Headers */,
|
||||
32F7C06F2030114C00873181 /* SDWebImageTransformer.h in Headers */,
|
||||
321B378D2083290E00C0EA77 /* SDWebImageLoadersManager.h in Headers */,
|
||||
324DF4B4200A14DC008A84CC /* SDWebImageDefine.h in Headers */,
|
||||
80377CE11F2F66A100F89830 /* common_sse2.h in Headers */,
|
||||
80377C0B1F2F665300F89830 /* random_utils.h in Headers */,
|
||||
|
@ -2892,6 +2935,7 @@
|
|||
323F8BE41F38EF770092B609 /* vp8li_enc.h in Headers */,
|
||||
320CAE152086F50500CFFC80 /* SDWebImageError.h in Headers */,
|
||||
323F8B861F38EF770092B609 /* histogram_enc.h in Headers */,
|
||||
321B37812083290E00C0EA77 /* SDWebImageLoader.h in Headers */,
|
||||
323F8BF61F38EF770092B609 /* animi.h in Headers */,
|
||||
321E60861F38E8C800405457 /* SDWebImageCoder.h in Headers */,
|
||||
321E60B01F38E90100405457 /* SDWebImageWebPCoder.h in Headers */,
|
||||
|
@ -3193,6 +3237,7 @@
|
|||
80377DD71F2F66A700F89830 /* lossless_sse2.c in Sources */,
|
||||
80377DA81F2F66A700F89830 /* alpha_processing_mips_dsp_r2.c in Sources */,
|
||||
80377DB11F2F66A700F89830 /* cost_mips_dsp_r2.c in Sources */,
|
||||
321B37962083290E00C0EA77 /* SDWebImageLoadersManager.m in Sources */,
|
||||
80377C581F2F666300F89830 /* random_utils.c in Sources */,
|
||||
323F8B591F38EF770092B609 /* config_enc.c in Sources */,
|
||||
80377DE91F2F66A700F89830 /* yuv_mips32.c in Sources */,
|
||||
|
@ -3252,6 +3297,7 @@
|
|||
80377C561F2F666300F89830 /* quant_levels_utils.c in Sources */,
|
||||
323F8BCF1F38EF770092B609 /* token_enc.c in Sources */,
|
||||
80377DD11F2F66A700F89830 /* lossless_enc_sse2.c in Sources */,
|
||||
321B378A2083290E00C0EA77 /* SDWebImageLoader.m in Sources */,
|
||||
32484772201775F600AF9E5A /* SDAnimatedImage.m in Sources */,
|
||||
323F8C1D1F38EF770092B609 /* muxread.c in Sources */,
|
||||
807A12311F89636300EC2A9B /* SDWebImageCodersManager.m in Sources */,
|
||||
|
@ -3395,6 +3441,7 @@
|
|||
80377E9C1F2F66D400F89830 /* idec_dec.c in Sources */,
|
||||
323F8B7B1F38EF770092B609 /* frame_enc.c in Sources */,
|
||||
80377D211F2F66A700F89830 /* alpha_processing_sse41.c in Sources */,
|
||||
321B37942083290E00C0EA77 /* SDWebImageLoadersManager.m in Sources */,
|
||||
323F8B8D1F38EF770092B609 /* iterator_enc.c in Sources */,
|
||||
3248475E201775F600AF9E5A /* SDAnimatedImageView.m in Sources */,
|
||||
80377D481F2F66A700F89830 /* lossless_enc_sse41.c in Sources */,
|
||||
|
@ -3455,6 +3502,7 @@
|
|||
80377E991F2F66D400F89830 /* buffer_dec.c in Sources */,
|
||||
80377C201F2F666300F89830 /* quant_levels_dec_utils.c in Sources */,
|
||||
32F7C07F2030719600873181 /* UIImage+Transform.m in Sources */,
|
||||
321B37882083290E00C0EA77 /* SDWebImageLoader.m in Sources */,
|
||||
80377D471F2F66A700F89830 /* lossless_enc_sse2.c in Sources */,
|
||||
80377C1E1F2F666300F89830 /* huffman_utils.c in Sources */,
|
||||
);
|
||||
|
@ -3559,6 +3607,7 @@
|
|||
80377DF01F2F66A800F89830 /* alpha_processing_sse41.c in Sources */,
|
||||
80377ECC1F2F66D500F89830 /* idec_dec.c in Sources */,
|
||||
323F8B7E1F38EF770092B609 /* frame_enc.c in Sources */,
|
||||
321B37972083290E00C0EA77 /* SDWebImageLoadersManager.m in Sources */,
|
||||
80377E171F2F66A800F89830 /* lossless_enc_sse41.c in Sources */,
|
||||
32484761201775F600AF9E5A /* SDAnimatedImageView.m in Sources */,
|
||||
323F8B901F38EF770092B609 /* iterator_enc.c in Sources */,
|
||||
|
@ -3619,6 +3668,7 @@
|
|||
80377EC91F2F66D500F89830 /* buffer_dec.c in Sources */,
|
||||
80377C6C1F2F666400F89830 /* huffman_utils.c in Sources */,
|
||||
32F7C0822030719600873181 /* UIImage+Transform.m in Sources */,
|
||||
321B378B2083290E00C0EA77 /* SDWebImageLoader.m in Sources */,
|
||||
80377E161F2F66A800F89830 /* lossless_enc_sse2.c in Sources */,
|
||||
431BB6C71D06D2C1006A3455 /* UIImageView+HighlightedWebCache.m in Sources */,
|
||||
);
|
||||
|
@ -3707,6 +3757,7 @@
|
|||
32F21B5C20788D8C0036B1D5 /* SDWebImageDownloaderRequestModifier.m in Sources */,
|
||||
32D122292080B2EB003685A3 /* SDWebImageCache.m in Sources */,
|
||||
80377E3B1F2F66A800F89830 /* cost_mips_dsp_r2.c in Sources */,
|
||||
321B378C2083290E00C0EA77 /* SDWebImageLoader.m in Sources */,
|
||||
4397D29B1D0DDD8C00BB2784 /* SDWebImageDownloader.m in Sources */,
|
||||
80377E711F2F66A800F89830 /* upsampling.c in Sources */,
|
||||
328BB6A72081FED200760D6C /* SDWebImageCacheKeyFilter.m in Sources */,
|
||||
|
@ -3784,6 +3835,7 @@
|
|||
323F8B851F38EF770092B609 /* histogram_enc.c in Sources */,
|
||||
80377EE51F2F66D500F89830 /* webp_dec.c in Sources */,
|
||||
4397D2B01D0DDD8C00BB2784 /* SDImageCache.m in Sources */,
|
||||
321B37982083290E00C0EA77 /* SDWebImageLoadersManager.m in Sources */,
|
||||
32F7C07A2030114C00873181 /* SDWebImageTransformer.m in Sources */,
|
||||
80377E4F1F2F66A800F89830 /* enc_sse41.c in Sources */,
|
||||
80377E701F2F66A800F89830 /* upsampling_sse2.c in Sources */,
|
||||
|
@ -3855,6 +3907,7 @@
|
|||
80377D921F2F66A700F89830 /* lossless_sse2.c in Sources */,
|
||||
80377D631F2F66A700F89830 /* alpha_processing_mips_dsp_r2.c in Sources */,
|
||||
80377D6C1F2F66A700F89830 /* cost_mips_dsp_r2.c in Sources */,
|
||||
321B37952083290E00C0EA77 /* SDWebImageLoadersManager.m in Sources */,
|
||||
4A2CAE361AB4BB7500B6BC39 /* UIImageView+WebCache.m in Sources */,
|
||||
323F8B581F38EF770092B609 /* config_enc.c in Sources */,
|
||||
43C892A21D9D6DDD0022038D /* demux.c in Sources */,
|
||||
|
@ -3914,6 +3967,7 @@
|
|||
4A2CAE191AB4BB6400B6BC39 /* SDWebImageCompat.m in Sources */,
|
||||
80377DA11F2F66A700F89830 /* upsampling_sse2.c in Sources */,
|
||||
323F8BCE1F38EF770092B609 /* token_enc.c in Sources */,
|
||||
321B37892083290E00C0EA77 /* SDWebImageLoader.m in Sources */,
|
||||
32484771201775F600AF9E5A /* SDAnimatedImage.m in Sources */,
|
||||
80377C3C1F2F666300F89830 /* quant_levels_utils.c in Sources */,
|
||||
323F8C1C1F38EF770092B609 /* muxread.c in Sources */,
|
||||
|
@ -4023,6 +4077,7 @@
|
|||
80377CD91F2F66A100F89830 /* alpha_processing_mips_dsp_r2.c in Sources */,
|
||||
80377CE21F2F66A100F89830 /* cost_mips_dsp_r2.c in Sources */,
|
||||
5376130B155AD0D5005750A4 /* SDWebImageDownloader.m in Sources */,
|
||||
321B37932083290E00C0EA77 /* SDWebImageLoadersManager.m in Sources */,
|
||||
323F8B561F38EF770092B609 /* config_enc.c in Sources */,
|
||||
43C8929B1D9D6DD70022038D /* demux.c in Sources */,
|
||||
80377D1A1F2F66A100F89830 /* yuv_mips32.c in Sources */,
|
||||
|
@ -4082,6 +4137,7 @@
|
|||
80377D171F2F66A100F89830 /* upsampling_sse2.c in Sources */,
|
||||
323F8BCC1F38EF770092B609 /* token_enc.c in Sources */,
|
||||
80377C081F2F665300F89830 /* quant_levels_utils.c in Sources */,
|
||||
321B37872083290E00C0EA77 /* SDWebImageLoader.m in Sources */,
|
||||
3248476F201775F600AF9E5A /* SDAnimatedImage.m in Sources */,
|
||||
323F8C1A1F38EF770092B609 /* muxread.c in Sources */,
|
||||
807A122E1F89636300EC2A9B /* SDWebImageCodersManager.m in Sources */,
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#import "SDWebImageOperation.h"
|
||||
#import "SDWebImageDownloaderConfig.h"
|
||||
#import "SDWebImageDownloaderRequestModifier.h"
|
||||
#import "SDWebImageLoader.h"
|
||||
|
||||
typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) {
|
||||
/**
|
||||
|
@ -86,9 +87,8 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) {
|
|||
FOUNDATION_EXPORT NSString * _Nonnull const SDWebImageDownloadStartNotification;
|
||||
FOUNDATION_EXPORT NSString * _Nonnull const SDWebImageDownloadStopNotification;
|
||||
|
||||
typedef void(^SDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL);
|
||||
|
||||
typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished);
|
||||
typedef SDWebImageLoaderProgressBlock SDWebImageDownloaderProgressBlock;
|
||||
typedef SDWebImageLoaderCompletedBlock SDWebImageDownloaderCompletedBlock;
|
||||
|
||||
/**
|
||||
* A token associated with each download. Can be used to cancel a download
|
||||
|
@ -245,3 +245,12 @@ typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage * _Nullable image, NSD
|
|||
- (void)invalidateSessionAndCancel:(BOOL)cancelPendingOperations;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/**
|
||||
SDWebImageDownloader is the built-in image downloader conform to `SDWebImageLoader`. Which provide the HTTP/HTTPS/FTP download, or local file URL using NSURLSession.
|
||||
However, this downloader does also support customization for advanced users. You can specify `operationClass` in download config to custom download operation, See `SDWebImageDownloaderOperation`.
|
||||
*/
|
||||
@interface SDWebImageDownloader (SDWebImageLoader) <SDWebImageLoader>
|
||||
|
||||
@end
|
||||
|
|
|
@ -462,3 +462,52 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation SDWebImageDownloader (SDWebImageLoader)
|
||||
|
||||
- (BOOL)canLoadWithURL:(NSURL *)url {
|
||||
if (!url) {
|
||||
return NO;
|
||||
}
|
||||
Class operationClass = self.config.operationClass;
|
||||
if (!operationClass || [operationClass isSubclassOfClass:[SDWebImageDownloaderOperation class]]) {
|
||||
// Built-in download operation class, checking all supported NSURLProtocol
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:url];
|
||||
NSArray<Class> *protocolClasses = self.sessionConfiguration.protocolClasses;
|
||||
for (Class protocolClass in protocolClasses) {
|
||||
if ([protocolClass isSubclassOfClass:[NSURLProtocol class]]) {
|
||||
BOOL canLoad = [protocolClass canInitWithRequest:request];
|
||||
if (canLoad) {
|
||||
return YES;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
// Custom download operation class may not dependent on NSURLSession, always pass YES.
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (id<SDWebImageOperation>)loadImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageLoaderProgressBlock)progressBlock completed:(SDWebImageLoaderCompletedBlock)completedBlock context:(SDWebImageContext *)context {
|
||||
SDWebImageDownloaderOptions downloaderOptions = 0;
|
||||
if (options & SDWebImageLowPriority) downloaderOptions |= SDWebImageDownloaderLowPriority;
|
||||
if (options & SDWebImageProgressiveDownload) downloaderOptions |= SDWebImageDownloaderProgressiveDownload;
|
||||
if (options & SDWebImageRefreshCached) downloaderOptions |= SDWebImageDownloaderUseNSURLCache;
|
||||
if (options & SDWebImageContinueInBackground) downloaderOptions |= SDWebImageDownloaderContinueInBackground;
|
||||
if (options & SDWebImageHandleCookies) downloaderOptions |= SDWebImageDownloaderHandleCookies;
|
||||
if (options & SDWebImageAllowInvalidSSLCertificates) downloaderOptions |= SDWebImageDownloaderAllowInvalidSSLCertificates;
|
||||
if (options & SDWebImageHighPriority) downloaderOptions |= SDWebImageDownloaderHighPriority;
|
||||
if (options & SDWebImageScaleDownLargeImages) downloaderOptions |= SDWebImageDownloaderScaleDownLargeImages;
|
||||
|
||||
if (options & SDWebImageRefreshCached) {
|
||||
// force progressive off if image already cached but forced refreshing
|
||||
downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;
|
||||
// ignore image read from NSURLCache if image if cached but force refreshing
|
||||
downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
|
||||
}
|
||||
|
||||
return [self downloadImageWithURL:url options:downloaderOptions context:context progress:progressBlock completed:completedBlock];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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 "SDWebImageCompat.h"
|
||||
#import "SDWebImageDefine.h"
|
||||
#import "SDWebImageOperation.h"
|
||||
|
||||
typedef void(^SDWebImageLoaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL);
|
||||
typedef void(^SDWebImageLoaderCompletedBlock)(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished);
|
||||
typedef void(^SDWebImageLoaderDataCompletedBlock)(NSData * _Nullable data, NSError * _Nullable error, BOOL finished);
|
||||
|
||||
/**
|
||||
A `SDImageCacheType` value to specify the cache type information from manager. `SDWebImageManager` will firstly query cache, then if cache miss or `SDWebImageRefreshCached` is set, it will start image loader to load the image.
|
||||
This can be a hint for image loader to load the image from network and refresh the image from remote location if needed. (NSNumber)
|
||||
*/
|
||||
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextLoaderCacheType;
|
||||
|
||||
@protocol SDWebImageLoader <NSObject>
|
||||
|
||||
- (BOOL)canLoadWithURL:(nullable NSURL *)url;
|
||||
|
||||
// We provide two ways to allow a image loader to load the image.
|
||||
// The first one should return the `UIImage` image instance as well as `NSData` image data. This is suitable for the use case such as progressive download from network, or image directlly from Photos framework.
|
||||
// The second one should return just the `NSData` image data, we will use the common image decoding logic to process the correct image instance, so the image loader itself can concentrate on only data retriving. This is suitable for the use case such as load the data from file.
|
||||
// Your image loader **MUST** implement at least one of those protocol, or an assert will occur. We will firstlly ask for `loadImageWithURL:options:progress:completed:context:` if you implement it. If this one return nil, we will continue to ask for `loadImageDataWithURL:options:progress:completed:context:` if you implement it.
|
||||
// @note It's your responsibility to load the image in the desired global queue(to avoid block main queue). We do not dispatch these method call in a global queue but just from the call queue (For `SDWebImageManager`, it typically call from the main queue).
|
||||
|
||||
@optional
|
||||
/**
|
||||
Load the image and image data with the given URL and return the image data. You're responsible for producing the image instance.
|
||||
|
||||
@param url The URL represent the image. Note this may not be a HTTP URL
|
||||
@param options A mask to specify options to use for this request
|
||||
@param context A context contains different options to perform specify changes or processes, see `SDWebImageContextOption`. This hold the extra objects which `options` enum can not hold.
|
||||
@param progressBlock A block called while image is downloading
|
||||
* @note the progress block is executed on a background queue
|
||||
@param completedBlock A block called when operation has been completed.
|
||||
@return An operation which allow the user to cancel the current request.
|
||||
*/
|
||||
- (nullable id<SDWebImageOperation>)loadImageWithURL:(nullable NSURL *)url
|
||||
options:(SDWebImageOptions)options
|
||||
context:(nullable SDWebImageContext *)context
|
||||
progress:(nullable SDWebImageLoaderProgressBlock)progressBlock
|
||||
completed:(nullable SDWebImageLoaderCompletedBlock)completedBlock;
|
||||
|
||||
/**
|
||||
Load the image with the given URL and return the image data. We will automatically handler the image decoding stuff for you.
|
||||
|
||||
@param url The URL represent the image. Note this may not be a HTTP URL
|
||||
@param options A mask to specify options to use for this request
|
||||
@param context A context contains different options to perform specify changes or processes, see `SDWebImageContextOption`. This hold the extra objects which `options` enum can not hold.
|
||||
@param progressBlock A block called while image is downloading
|
||||
* @note the progress block is executed on a background queue
|
||||
@param completedBlock A block called when operation has been completed.
|
||||
@return An operation which allow the user to cancel the current request.
|
||||
*/
|
||||
- (nullable id<SDWebImageOperation>)loadImageDataWithURL:(nullable NSURL *)url
|
||||
options:(SDWebImageOptions)options
|
||||
context:(nullable SDWebImageContext *)context
|
||||
progress:(nullable SDWebImageLoaderProgressBlock)progressBlock
|
||||
completed:(nullable SDWebImageLoaderDataCompletedBlock)completedBlock;
|
||||
|
||||
@end
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* 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 "SDWebImageLoader.h"
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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 "SDWebImageLoader.h"
|
||||
|
||||
@interface SDWebImageLoadersManager : NSObject <SDWebImageLoader>
|
||||
|
||||
@property (nonatomic, class, readonly, nonnull) SDWebImageLoadersManager *sharedManager;
|
||||
|
||||
/**
|
||||
All image loaders in manager. The loaders array is a priority queue, which means the later added loader will have the highest priority
|
||||
*/
|
||||
@property (nonatomic, strong, readwrite, nullable) NSArray<id<SDWebImageLoader>>* loaders;
|
||||
|
||||
/**
|
||||
Add a new image loader to the end of loaders array. Which has the highest priority.
|
||||
|
||||
@param loader loader
|
||||
*/
|
||||
- (void)addLoader:(nonnull id<SDWebImageLoader>)loader;
|
||||
|
||||
/**
|
||||
Remove a image loader in the loaders array.
|
||||
|
||||
@param loader loader
|
||||
*/
|
||||
- (void)removeLoader:(nonnull id<SDWebImageLoader>)loader;
|
||||
|
||||
@end
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* 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 "SDWebImageLoadersManager.h"
|
||||
#import "SDWebImageDownloader.h"
|
||||
|
||||
#define LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
|
||||
#define UNLOCK(lock) dispatch_semaphore_signal(lock);
|
||||
|
||||
@interface SDWebImageLoadersManager ()
|
||||
|
||||
@property (strong, nonatomic, nonnull) NSMutableArray<id<SDWebImageLoader>> *mutableLoaders;
|
||||
@property (nonatomic, strong, nonnull) dispatch_semaphore_t loadersLock;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SDWebImageLoadersManager
|
||||
|
||||
+ (SDWebImageLoadersManager *)sharedManager {
|
||||
static dispatch_once_t onceToken;
|
||||
static SDWebImageLoadersManager *manager;
|
||||
dispatch_once(&onceToken, ^{
|
||||
manager = [[SDWebImageLoadersManager alloc] init];
|
||||
});
|
||||
return manager;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
// initialize with default image loaders
|
||||
self.mutableLoaders = [@[[SDWebImageDownloader sharedDownloader]] mutableCopy];
|
||||
self.loadersLock = dispatch_semaphore_create(1);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Loader Property
|
||||
|
||||
- (void)addLoader:(id<SDWebImageLoader>)loader {
|
||||
if ([loader conformsToProtocol:@protocol(SDWebImageLoader)]) {
|
||||
LOCK(self.loadersLock);
|
||||
[self.mutableLoaders addObject:loader];
|
||||
UNLOCK(self.loadersLock);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeLoader:(id<SDWebImageLoader>)loader {
|
||||
LOCK(self.loadersLock);
|
||||
[self.mutableLoaders removeObject:loader];
|
||||
UNLOCK(self.loadersLock);
|
||||
}
|
||||
|
||||
- (NSArray<id<SDWebImageLoader>> *)loaders {
|
||||
NSArray<id<SDWebImageLoader>> *sortedLoaders;
|
||||
LOCK(self.loadersLock);
|
||||
sortedLoaders = [[[self.mutableLoaders copy] reverseObjectEnumerator] allObjects];
|
||||
UNLOCK(self.loadersLock);
|
||||
return sortedLoaders;
|
||||
}
|
||||
|
||||
- (void)setLoaders:(NSArray<id<SDWebImageLoader>> *)loaders {
|
||||
LOCK(self.loadersLock);
|
||||
self.mutableLoaders = [loaders mutableCopy];
|
||||
UNLOCK(self.loadersLock);
|
||||
}
|
||||
|
||||
#pragma mark - SDWebImageLoader
|
||||
|
||||
- (BOOL)canLoadWithURL:(nullable NSURL *)url {
|
||||
for (id<SDWebImageLoader> loader in self.loaders) {
|
||||
if ([loader canLoadWithURL:url]) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (id<SDWebImageOperation>)loadImageWithURL:(NSURL *)url options:(SDWebImageOptions)options context:(SDWebImageContext *)context progress:(SDWebImageLoaderProgressBlock)progressBlock completed:(SDWebImageLoaderCompletedBlock)completedBlock {
|
||||
if (!url) {
|
||||
return nil;
|
||||
}
|
||||
for (id<SDWebImageLoader> loader in self.loaders) {
|
||||
if ([loader respondsToSelector:@selector(loadImageWithURL:options:context:progress:completed:)]) {
|
||||
if ([loader canLoadWithURL:url]) {
|
||||
return [loader loadImageWithURL:url options:options context:context progress:progressBlock completed:completedBlock];
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id<SDWebImageOperation>)loadImageDataWithURL:(NSURL *)url options:(SDWebImageOptions)options context:(SDWebImageContext *)context progress:(SDWebImageLoaderProgressBlock)progressBlock completed:(SDWebImageLoaderDataCompletedBlock)completedBlock {
|
||||
if (!url) {
|
||||
return nil;
|
||||
}
|
||||
for (id<SDWebImageLoader> loader in self.loaders) {
|
||||
if ([loader respondsToSelector:@selector(loadImageDataWithURL:options:context:progress:completed:)]) {
|
||||
if ([loader canLoadWithURL:url]) {
|
||||
return [loader loadImageDataWithURL:url options:options context:context progress:progressBlock completed:completedBlock];
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
|
@ -13,6 +13,7 @@
|
|||
#import "SDWebImageTransformer.h"
|
||||
#import "SDWebImageCacheKeyFilter.h"
|
||||
#import "SDWebImageCacheSerializer.h"
|
||||
#import "SDWebImageLoader.h"
|
||||
|
||||
typedef void(^SDExternalCompletionBlock)(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL);
|
||||
|
||||
|
@ -105,7 +106,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
|||
* The image downloader used by manager to download image.
|
||||
* @note If you specify a non-shared downloader, don't forget to call `invalidateSessionAndCancel:` at proper time to avoid memory leak.
|
||||
*/
|
||||
@property (strong, nonatomic, readonly, nonnull) SDWebImageDownloader *imageDownloader;
|
||||
@property (strong, nonatomic, readonly, nonnull) id<SDWebImageLoader> imageDownloader;
|
||||
|
||||
/**
|
||||
The image transformer for manager. It's used for image transform after the image load finished and store the transformed image to cache, see `SDWebImageTransformer`.
|
||||
|
@ -175,7 +176,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
|||
* Allows to specify instance of cache and image downloader used with image manager.
|
||||
* @return new instance of `SDWebImageManager` with specified cache and downloader.
|
||||
*/
|
||||
- (nonnull instancetype)initWithCache:(nonnull id<SDWebImageCache>)cache downloader:(nonnull SDWebImageDownloader *)downloader NS_DESIGNATED_INITIALIZER;
|
||||
- (nonnull instancetype)initWithCache:(nonnull id<SDWebImageCache>)cache downloader:(nonnull id<SDWebImageLoader>)downloader NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
/**
|
||||
* Downloads the image at the given URL if not present in cache or return the cached version otherwise.
|
||||
|
|
|
@ -28,7 +28,7 @@ static SDWebImageDownloader *_defaultImageDownloader;
|
|||
@interface SDWebImageManager ()
|
||||
|
||||
@property (strong, nonatomic, readwrite, nonnull) SDImageCache *imageCache;
|
||||
@property (strong, nonatomic, readwrite, nonnull) SDWebImageDownloader *imageDownloader;
|
||||
@property (strong, nonatomic, readwrite, nonnull) id<SDWebImageLoader> imageDownloader;
|
||||
@property (strong, nonatomic, nonnull) NSMutableSet<NSURL *> *failedURLs;
|
||||
@property (strong, nonatomic, nonnull) NSMutableArray<SDWebImageCombinedOperation *> *runningOperations;
|
||||
|
||||
|
@ -79,7 +79,7 @@ static SDWebImageDownloader *_defaultImageDownloader;
|
|||
return [self initWithCache:cache downloader:downloader];
|
||||
}
|
||||
|
||||
- (nonnull instancetype)initWithCache:(nonnull id<SDWebImageCache>)cache downloader:(nonnull SDWebImageDownloader *)downloader {
|
||||
- (nonnull instancetype)initWithCache:(nonnull id<SDWebImageCache>)cache downloader:(nonnull id<SDWebImageLoader>)downloader {
|
||||
if ((self = [super init])) {
|
||||
_imageCache = cache;
|
||||
_imageDownloader = downloader;
|
||||
|
@ -201,30 +201,10 @@ static SDWebImageDownloader *_defaultImageDownloader;
|
|||
// AND try to re-download it in order to let a chance to NSURLCache to refresh it from server.
|
||||
[self callCompletionBlockForOperation:strongOperation completion:completedBlock image:cachedImage data:cachedData error:nil cacheType:cacheType finished:YES url:url];
|
||||
}
|
||||
|
||||
// download if no image or requested to refresh anyway, and download allowed by delegate
|
||||
SDWebImageDownloaderOptions downloaderOptions = 0;
|
||||
if (options & SDWebImageLowPriority) downloaderOptions |= SDWebImageDownloaderLowPriority;
|
||||
if (options & SDWebImageProgressiveDownload) downloaderOptions |= SDWebImageDownloaderProgressiveDownload;
|
||||
if (options & SDWebImageRefreshCached) downloaderOptions |= SDWebImageDownloaderUseNSURLCache;
|
||||
if (options & SDWebImageContinueInBackground) downloaderOptions |= SDWebImageDownloaderContinueInBackground;
|
||||
if (options & SDWebImageHandleCookies) downloaderOptions |= SDWebImageDownloaderHandleCookies;
|
||||
if (options & SDWebImageAllowInvalidSSLCertificates) downloaderOptions |= SDWebImageDownloaderAllowInvalidSSLCertificates;
|
||||
if (options & SDWebImageHighPriority) downloaderOptions |= SDWebImageDownloaderHighPriority;
|
||||
if (options & SDWebImageScaleDownLargeImages) downloaderOptions |= SDWebImageDownloaderScaleDownLargeImages;
|
||||
if (options & SDWebImageDecodeFirstFrameOnly) downloaderOptions |= SDWebImageDownloaderDecodeFirstFrameOnly;
|
||||
if (options & SDWebImagePreloadAllFrames) downloaderOptions |= SDWebImageDownloaderPreloadAllFrames;
|
||||
|
||||
if (cachedImage && options & SDWebImageRefreshCached) {
|
||||
// force progressive off if image already cached but forced refreshing
|
||||
downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;
|
||||
// ignore image read from NSURLCache if image if cached but force refreshing
|
||||
downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
|
||||
}
|
||||
|
||||
// `SDWebImageCombinedOperation` -> `SDWebImageDownloadToken` -> `downloadOperationCancelToken`, which is a `SDCallbacksDictionary` and retain the completed block below, so we need weak-strong again to avoid retain cycle
|
||||
__weak typeof(strongOperation) weakSubOperation = strongOperation;
|
||||
strongOperation.downloadOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions context:context progress:progressBlock completed:^(UIImage *downloadedImage, NSData *downloadedData, NSError *error, BOOL finished) {
|
||||
strongOperation.downloadOperation = [self.imageDownloader loadImageWithURL:url options:options context:context progress:progressBlock completed:^(UIImage *downloadedImage, NSData *downloadedData, NSError *error, BOOL finished) {
|
||||
__strong typeof(weakSubOperation) strongSubOperation = weakSubOperation;
|
||||
if (!strongSubOperation || strongSubOperation.isCancelled) {
|
||||
// Do nothing if the operation was cancelled
|
||||
|
@ -264,12 +244,6 @@ static SDWebImageDownloader *_defaultImageDownloader;
|
|||
if (options & SDWebImageCacheMemoryOnly) {
|
||||
storeCacheType = SDImageCacheTypeMemory;
|
||||
}
|
||||
|
||||
// We've done the scale process in SDWebImageDownloader with the shared manager, this is used for custom manager and avoid extra scale.
|
||||
if (self != [SDWebImageManager sharedManager] && cacheKeyFilter && downloadedImage && ![downloadedImage conformsToProtocol:@protocol(SDAnimatedImage)]) {
|
||||
downloadedImage = [self scaledImageForKey:key image:downloadedImage];
|
||||
}
|
||||
|
||||
if (options & SDWebImageRefreshCached && cachedImage && !downloadedImage) {
|
||||
// Image refresh hit the NSURLCache cache, do not call the completion block
|
||||
} else if (downloadedImage && (!downloadedImage.sd_isAnimated || (options & SDWebImageTransformAnimatedImage)) && transformer) {
|
||||
|
|
|
@ -36,6 +36,8 @@ FOUNDATION_EXPORT const unsigned char WebImageVersionString[];
|
|||
#import <SDWebImage/SDWebImageDownloaderConfig.h>
|
||||
#import <SDWebImage/SDWebImageDownloaderOperation.h>
|
||||
#import <SDWebImage/SDWebImageDownloaderRequestModifier.h>
|
||||
#import <SDWebImage/SDWebImageLoader.h>
|
||||
#import <SDWebImage/SDWebImageLoadersManager.h>
|
||||
#import <SDWebImage/UIButton+WebCache.h>
|
||||
#import <SDWebImage/SDWebImagePrefetcher.h>
|
||||
#import <SDWebImage/UIView+WebCacheOperation.h>
|
||||
|
|
Loading…
Reference in New Issue