Commit 47cd917983f56871a55f20abeabfcd26976aaef6

Authored by 张旭
1 parent 4136d3d7

修改监测宏 原生页面

Showing 37 changed files with 5680 additions and 11 deletions
VLionADSDKDemo/VLionADSDKDemo.xcodeproj/project.pbxproj
... ... @@ -11,6 +11,23 @@
11 11 81DC51D31F95FB7E0060EBE3 /* NativeAdListsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 81DC51D01F95FB7D0060EBE3 /* NativeAdListsController.m */; };
12 12 81DC51D41F95FB7E0060EBE3 /* BannerADController.m in Sources */ = {isa = PBXBuildFile; fileRef = 81DC51D21F95FB7E0060EBE3 /* BannerADController.m */; };
13 13 D2188EA41F9F1CA8006BF9C8 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2188EA31F9F1CA8006BF9C8 /* ViewController.m */; };
  14 + D29BFE621FCFB0F500D3EE1B /* MKAnnotationView+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE421FCFB0F500D3EE1B /* MKAnnotationView+WebCache.m */; };
  15 + D29BFE631FCFB0F500D3EE1B /* NSData+ImageContentType.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE441FCFB0F500D3EE1B /* NSData+ImageContentType.m */; };
  16 + D29BFE641FCFB0F500D3EE1B /* SDImageCache.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE461FCFB0F500D3EE1B /* SDImageCache.m */; };
  17 + D29BFE651FCFB0F500D3EE1B /* SDWebImageCompat.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE481FCFB0F500D3EE1B /* SDWebImageCompat.m */; };
  18 + D29BFE661FCFB0F500D3EE1B /* SDWebImageDecoder.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE4A1FCFB0F500D3EE1B /* SDWebImageDecoder.m */; };
  19 + D29BFE671FCFB0F500D3EE1B /* SDWebImageDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE4C1FCFB0F500D3EE1B /* SDWebImageDownloader.m */; };
  20 + D29BFE681FCFB0F500D3EE1B /* SDWebImageDownloaderOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE4E1FCFB0F500D3EE1B /* SDWebImageDownloaderOperation.m */; };
  21 + D29BFE691FCFB0F500D3EE1B /* SDWebImageManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE501FCFB0F500D3EE1B /* SDWebImageManager.m */; };
  22 + D29BFE6A1FCFB0F500D3EE1B /* SDWebImagePrefetcher.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE531FCFB0F500D3EE1B /* SDWebImagePrefetcher.m */; };
  23 + D29BFE6B1FCFB0F500D3EE1B /* UIButton+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE551FCFB0F500D3EE1B /* UIButton+WebCache.m */; };
  24 + D29BFE6C1FCFB0F500D3EE1B /* UIImage+GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE571FCFB0F500D3EE1B /* UIImage+GIF.m */; };
  25 + D29BFE6D1FCFB0F500D3EE1B /* UIImage+MultiFormat.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE591FCFB0F500D3EE1B /* UIImage+MultiFormat.m */; };
  26 + D29BFE6E1FCFB0F500D3EE1B /* UIImage+WebP.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE5B1FCFB0F500D3EE1B /* UIImage+WebP.m */; };
  27 + D29BFE6F1FCFB0F500D3EE1B /* UIImageView+HighlightedWebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE5D1FCFB0F500D3EE1B /* UIImageView+HighlightedWebCache.m */; };
  28 + D29BFE701FCFB0F500D3EE1B /* UIImageView+WebCache.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE5F1FCFB0F500D3EE1B /* UIImageView+WebCache.m */; };
  29 + D29BFE711FCFB0F500D3EE1B /* UIView+WebCacheOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE611FCFB0F500D3EE1B /* UIView+WebCacheOperation.m */; };
  30 + D29BFE741FCFB14B00D3EE1B /* UIView+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = D29BFE731FCFB14A00D3EE1B /* UIView+Extension.m */; };
14 31 D2ED41651F95F3BD00803E9D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D2ED41641F95F3BD00803E9D /* AppDelegate.m */; };
15 32 D2ED416B1F95F3BD00803E9D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D2ED41691F95F3BD00803E9D /* Main.storyboard */; };
16 33 D2ED416D1F95F3BD00803E9D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D2ED416C1F95F3BD00803E9D /* Assets.xcassets */; };
... ... @@ -41,6 +58,41 @@
41 58 81DC51D11F95FB7E0060EBE3 /* BannerADController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BannerADController.h; sourceTree = "<group>"; };
42 59 81DC51D21F95FB7E0060EBE3 /* BannerADController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BannerADController.m; sourceTree = "<group>"; };
43 60 D2188EA31F9F1CA8006BF9C8 /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
  61 + D29BFE411FCFB0F500D3EE1B /* MKAnnotationView+WebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MKAnnotationView+WebCache.h"; sourceTree = "<group>"; };
  62 + D29BFE421FCFB0F500D3EE1B /* MKAnnotationView+WebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MKAnnotationView+WebCache.m"; sourceTree = "<group>"; };
  63 + D29BFE431FCFB0F500D3EE1B /* NSData+ImageContentType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+ImageContentType.h"; sourceTree = "<group>"; };
  64 + D29BFE441FCFB0F500D3EE1B /* NSData+ImageContentType.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+ImageContentType.m"; sourceTree = "<group>"; };
  65 + D29BFE451FCFB0F500D3EE1B /* SDImageCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDImageCache.h; sourceTree = "<group>"; };
  66 + D29BFE461FCFB0F500D3EE1B /* SDImageCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDImageCache.m; sourceTree = "<group>"; };
  67 + D29BFE471FCFB0F500D3EE1B /* SDWebImageCompat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageCompat.h; sourceTree = "<group>"; };
  68 + D29BFE481FCFB0F500D3EE1B /* SDWebImageCompat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageCompat.m; sourceTree = "<group>"; };
  69 + D29BFE491FCFB0F500D3EE1B /* SDWebImageDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageDecoder.h; sourceTree = "<group>"; };
  70 + D29BFE4A1FCFB0F500D3EE1B /* SDWebImageDecoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageDecoder.m; sourceTree = "<group>"; };
  71 + D29BFE4B1FCFB0F500D3EE1B /* SDWebImageDownloader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageDownloader.h; sourceTree = "<group>"; };
  72 + D29BFE4C1FCFB0F500D3EE1B /* SDWebImageDownloader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageDownloader.m; sourceTree = "<group>"; };
  73 + D29BFE4D1FCFB0F500D3EE1B /* SDWebImageDownloaderOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageDownloaderOperation.h; sourceTree = "<group>"; };
  74 + D29BFE4E1FCFB0F500D3EE1B /* SDWebImageDownloaderOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageDownloaderOperation.m; sourceTree = "<group>"; };
  75 + D29BFE4F1FCFB0F500D3EE1B /* SDWebImageManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageManager.h; sourceTree = "<group>"; };
  76 + D29BFE501FCFB0F500D3EE1B /* SDWebImageManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageManager.m; sourceTree = "<group>"; };
  77 + D29BFE511FCFB0F500D3EE1B /* SDWebImageOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageOperation.h; sourceTree = "<group>"; };
  78 + D29BFE521FCFB0F500D3EE1B /* SDWebImagePrefetcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImagePrefetcher.h; sourceTree = "<group>"; };
  79 + D29BFE531FCFB0F500D3EE1B /* SDWebImagePrefetcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImagePrefetcher.m; sourceTree = "<group>"; };
  80 + D29BFE541FCFB0F500D3EE1B /* UIButton+WebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIButton+WebCache.h"; sourceTree = "<group>"; };
  81 + D29BFE551FCFB0F500D3EE1B /* UIButton+WebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIButton+WebCache.m"; sourceTree = "<group>"; };
  82 + D29BFE561FCFB0F500D3EE1B /* UIImage+GIF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+GIF.h"; sourceTree = "<group>"; };
  83 + D29BFE571FCFB0F500D3EE1B /* UIImage+GIF.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+GIF.m"; sourceTree = "<group>"; };
  84 + D29BFE581FCFB0F500D3EE1B /* UIImage+MultiFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+MultiFormat.h"; sourceTree = "<group>"; };
  85 + D29BFE591FCFB0F500D3EE1B /* UIImage+MultiFormat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+MultiFormat.m"; sourceTree = "<group>"; };
  86 + D29BFE5A1FCFB0F500D3EE1B /* UIImage+WebP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+WebP.h"; sourceTree = "<group>"; };
  87 + D29BFE5B1FCFB0F500D3EE1B /* UIImage+WebP.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+WebP.m"; sourceTree = "<group>"; };
  88 + D29BFE5C1FCFB0F500D3EE1B /* UIImageView+HighlightedWebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImageView+HighlightedWebCache.h"; sourceTree = "<group>"; };
  89 + D29BFE5D1FCFB0F500D3EE1B /* UIImageView+HighlightedWebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+HighlightedWebCache.m"; sourceTree = "<group>"; };
  90 + D29BFE5E1FCFB0F500D3EE1B /* UIImageView+WebCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImageView+WebCache.h"; sourceTree = "<group>"; };
  91 + D29BFE5F1FCFB0F500D3EE1B /* UIImageView+WebCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+WebCache.m"; sourceTree = "<group>"; };
  92 + D29BFE601FCFB0F500D3EE1B /* UIView+WebCacheOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+WebCacheOperation.h"; sourceTree = "<group>"; };
  93 + D29BFE611FCFB0F500D3EE1B /* UIView+WebCacheOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+WebCacheOperation.m"; sourceTree = "<group>"; };
  94 + D29BFE721FCFB14A00D3EE1B /* UIView+Extension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Extension.h"; sourceTree = "<group>"; };
  95 + D29BFE731FCFB14A00D3EE1B /* UIView+Extension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Extension.m"; sourceTree = "<group>"; };
44 96 D2ED41601F95F3BD00803E9D /* VLionAdSDKDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VLionAdSDKDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
45 97 D2ED41631F95F3BD00803E9D /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
46 98 D2ED41641F95F3BD00803E9D /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
... ... @@ -72,6 +124,46 @@
72 124 name = Frameworks;
73 125 sourceTree = "<group>";
74 126 };
  127 + D29BFE401FCFB0F500D3EE1B /* SDWebImage */ = {
  128 + isa = PBXGroup;
  129 + children = (
  130 + D29BFE411FCFB0F500D3EE1B /* MKAnnotationView+WebCache.h */,
  131 + D29BFE421FCFB0F500D3EE1B /* MKAnnotationView+WebCache.m */,
  132 + D29BFE431FCFB0F500D3EE1B /* NSData+ImageContentType.h */,
  133 + D29BFE441FCFB0F500D3EE1B /* NSData+ImageContentType.m */,
  134 + D29BFE451FCFB0F500D3EE1B /* SDImageCache.h */,
  135 + D29BFE461FCFB0F500D3EE1B /* SDImageCache.m */,
  136 + D29BFE471FCFB0F500D3EE1B /* SDWebImageCompat.h */,
  137 + D29BFE481FCFB0F500D3EE1B /* SDWebImageCompat.m */,
  138 + D29BFE491FCFB0F500D3EE1B /* SDWebImageDecoder.h */,
  139 + D29BFE4A1FCFB0F500D3EE1B /* SDWebImageDecoder.m */,
  140 + D29BFE4B1FCFB0F500D3EE1B /* SDWebImageDownloader.h */,
  141 + D29BFE4C1FCFB0F500D3EE1B /* SDWebImageDownloader.m */,
  142 + D29BFE4D1FCFB0F500D3EE1B /* SDWebImageDownloaderOperation.h */,
  143 + D29BFE4E1FCFB0F500D3EE1B /* SDWebImageDownloaderOperation.m */,
  144 + D29BFE4F1FCFB0F500D3EE1B /* SDWebImageManager.h */,
  145 + D29BFE501FCFB0F500D3EE1B /* SDWebImageManager.m */,
  146 + D29BFE511FCFB0F500D3EE1B /* SDWebImageOperation.h */,
  147 + D29BFE521FCFB0F500D3EE1B /* SDWebImagePrefetcher.h */,
  148 + D29BFE531FCFB0F500D3EE1B /* SDWebImagePrefetcher.m */,
  149 + D29BFE541FCFB0F500D3EE1B /* UIButton+WebCache.h */,
  150 + D29BFE551FCFB0F500D3EE1B /* UIButton+WebCache.m */,
  151 + D29BFE561FCFB0F500D3EE1B /* UIImage+GIF.h */,
  152 + D29BFE571FCFB0F500D3EE1B /* UIImage+GIF.m */,
  153 + D29BFE581FCFB0F500D3EE1B /* UIImage+MultiFormat.h */,
  154 + D29BFE591FCFB0F500D3EE1B /* UIImage+MultiFormat.m */,
  155 + D29BFE5A1FCFB0F500D3EE1B /* UIImage+WebP.h */,
  156 + D29BFE5B1FCFB0F500D3EE1B /* UIImage+WebP.m */,
  157 + D29BFE5C1FCFB0F500D3EE1B /* UIImageView+HighlightedWebCache.h */,
  158 + D29BFE5D1FCFB0F500D3EE1B /* UIImageView+HighlightedWebCache.m */,
  159 + D29BFE5E1FCFB0F500D3EE1B /* UIImageView+WebCache.h */,
  160 + D29BFE5F1FCFB0F500D3EE1B /* UIImageView+WebCache.m */,
  161 + D29BFE601FCFB0F500D3EE1B /* UIView+WebCacheOperation.h */,
  162 + D29BFE611FCFB0F500D3EE1B /* UIView+WebCacheOperation.m */,
  163 + );
  164 + path = SDWebImage;
  165 + sourceTree = "<group>";
  166 + };
75 167 D2ED41571F95F3BD00803E9D = {
76 168 isa = PBXGroup;
77 169 children = (
... ... @@ -94,6 +186,7 @@
94 186 children = (
95 187 DCE2504C1FBC4A1900E27BDE /* VLionADSDK.framework */,
96 188 817BA9931F9606AB00599550 /* VLionAdImg.bundle */,
  189 + D29BFE401FCFB0F500D3EE1B /* SDWebImage */,
97 190 D2ED41631F95F3BD00803E9D /* AppDelegate.h */,
98 191 D2ED41641F95F3BD00803E9D /* AppDelegate.m */,
99 192 D2ED41661F95F3BD00803E9D /* ViewController.h */,
... ... @@ -102,6 +195,8 @@
102 195 81DC51D21F95FB7E0060EBE3 /* BannerADController.m */,
103 196 81DC51CF1F95FB7D0060EBE3 /* NativeAdListsController.h */,
104 197 81DC51D01F95FB7D0060EBE3 /* NativeAdListsController.m */,
  198 + D29BFE721FCFB14A00D3EE1B /* UIView+Extension.h */,
  199 + D29BFE731FCFB14A00D3EE1B /* UIView+Extension.m */,
105 200 D2ED41691F95F3BD00803E9D /* Main.storyboard */,
106 201 D2ED416C1F95F3BD00803E9D /* Assets.xcassets */,
107 202 D2ED416E1F95F3BD00803E9D /* LaunchScreen.storyboard */,
... ... @@ -155,7 +250,7 @@
155 250 };
156 251 };
157 252 };
158   - buildConfigurationList = D2ED415B1F95F3BD00803E9D /* Build configuration list for PBXProject "VLionADSDKDemo" */;
  253 + buildConfigurationList = D2ED415B1F95F3BD00803E9D /* Build configuration list for PBXProject "VLionAdSDKDemo" */;
159 254 compatibilityVersion = "Xcode 8.0";
160 255 developmentRegion = en;
161 256 hasScannedForEncodings = 0;
... ... @@ -193,10 +288,27 @@
193 288 buildActionMask = 2147483647;
194 289 files = (
195 290 D2ED41731F95F3BD00803E9D /* main.m in Sources */,
  291 + D29BFE6F1FCFB0F500D3EE1B /* UIImageView+HighlightedWebCache.m in Sources */,
  292 + D29BFE741FCFB14B00D3EE1B /* UIView+Extension.m in Sources */,
  293 + D29BFE701FCFB0F500D3EE1B /* UIImageView+WebCache.m in Sources */,
  294 + D29BFE6E1FCFB0F500D3EE1B /* UIImage+WebP.m in Sources */,
  295 + D29BFE6A1FCFB0F500D3EE1B /* SDWebImagePrefetcher.m in Sources */,
196 296 D2ED41651F95F3BD00803E9D /* AppDelegate.m in Sources */,
  297 + D29BFE661FCFB0F500D3EE1B /* SDWebImageDecoder.m in Sources */,
  298 + D29BFE671FCFB0F500D3EE1B /* SDWebImageDownloader.m in Sources */,
197 299 81DC51D41F95FB7E0060EBE3 /* BannerADController.m in Sources */,
  300 + D29BFE691FCFB0F500D3EE1B /* SDWebImageManager.m in Sources */,
  301 + D29BFE711FCFB0F500D3EE1B /* UIView+WebCacheOperation.m in Sources */,
  302 + D29BFE6B1FCFB0F500D3EE1B /* UIButton+WebCache.m in Sources */,
  303 + D29BFE6D1FCFB0F500D3EE1B /* UIImage+MultiFormat.m in Sources */,
198 304 81DC51D31F95FB7E0060EBE3 /* NativeAdListsController.m in Sources */,
  305 + D29BFE681FCFB0F500D3EE1B /* SDWebImageDownloaderOperation.m in Sources */,
  306 + D29BFE6C1FCFB0F500D3EE1B /* UIImage+GIF.m in Sources */,
  307 + D29BFE651FCFB0F500D3EE1B /* SDWebImageCompat.m in Sources */,
  308 + D29BFE631FCFB0F500D3EE1B /* NSData+ImageContentType.m in Sources */,
199 309 D2188EA41F9F1CA8006BF9C8 /* ViewController.m in Sources */,
  310 + D29BFE621FCFB0F500D3EE1B /* MKAnnotationView+WebCache.m in Sources */,
  311 + D29BFE641FCFB0F500D3EE1B /* SDImageCache.m in Sources */,
200 312 );
201 313 runOnlyForDeploymentPostprocessing = 0;
202 314 };
... ... @@ -387,7 +499,7 @@
387 499 /* End XCBuildConfiguration section */
388 500  
389 501 /* Begin XCConfigurationList section */
390   - D2ED415B1F95F3BD00803E9D /* Build configuration list for PBXProject "VLionADSDKDemo" */ = {
  502 + D2ED415B1F95F3BD00803E9D /* Build configuration list for PBXProject "VLionAdSDKDemo" */ = {
391 503 isa = XCConfigurationList;
392 504 buildConfigurations = (
393 505 D2ED41741F95F3BD00803E9D /* Debug */,
... ...
VLionADSDKDemo/VLionADSDKDemo/NativeAdListsController.m
... ... @@ -8,12 +8,24 @@
8 8  
9 9 #import "NativeAdListsController.h"
10 10 #import <VLionAdSDK/VLionAdSDK.h>
11   -
  11 +#import "UIView+Extension.h"
  12 +#import "UIImageView+WebCache.h"
  13 +#define IPHONEX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
12 14 #define H_SPACE (self.view.bounds.size.height-250)/2
13 15  
14 16 @interface NativeAdListsController ()
15   -
  17 +{
  18 + VLionNativeAdShufflingModel* shuModel;
  19 + VLionNativeAdInformationFlowModel* infoModel;
  20 + VLionNativeAdNewsModel* newsModel;
  21 + VLionNativeAdAppWallModel* appWallModel;
  22 + VLionNativeAdWaterfallModel* waterModel;
  23 + NSString *_imgUrl;
  24 + id currentMdl;
  25 +}
16 26 @property (nonatomic, strong) UIButton *closeBtn;
  27 +@property (nonatomic, strong) UIButton *xuanRanBtn;
  28 +@property (nonatomic, strong) UIImageView *imgView;
17 29  
18 30 @end
19 31  
... ... @@ -28,13 +40,15 @@
28 40 bg.image = [UIImage imageNamed:@"bg_activity"];
29 41 [self.view addSubview:bg];
30 42  
  43 + [self.view addSubview:self.xuanRanBtn];
31 44 [self.view addSubview:self.closeBtn];
  45 + [self.view addSubview:self.imgView];
32 46  
33 47 NSArray *titleArr = @[@"原生新闻广告数据",@"原生应用墙广告数据",@"原生轮播图广告数据",@"原生瀑布流广告数据",@"原生信息流广告数据"];
34 48  
35 49 for (int i = 0; i < titleArr.count; i ++) {
36 50 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
37   - button.frame = CGRectMake((self.view.bounds.size.width-200)/2, (30+40)*i+H_SPACE, 200, 40);
  51 + button.frame = CGRectMake((self.view.bounds.size.width-200)/2, ((IPHONEX ? 30 : 15)+40)*i+H_SPACE+(IPHONEX ? 100 : 120), 200, 40);
38 52 [button setTitle:titleArr[i] forState:UIControlStateNormal];
39 53 button.titleLabel.font = [UIFont systemFontOfSize:16];
40 54 [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
... ... @@ -48,7 +62,7 @@
48 62 }
49 63  
50 64 - (void)adButtonAction:(UIButton *)button {
51   -
  65 + self.imgView.hidden = YES;
52 66 switch (button.tag) {
53 67 case 10000: {//新闻
54 68 [[VLionManager manager] vl_nativeAdNewsWithTagId:@"" handler:^(VLionNativeAdNewsModel * _Nullable adModel, NSDictionary * _Nullable errorDic) {
... ... @@ -56,12 +70,16 @@
56 70 if (errorDic) {
57 71 NSString *tagid = [NSString stringWithFormat:@"%d",adModel.tagid];
58 72 if(adModel.tagid == 0)
59   - {
60   - tagid = @"null";
61   - }
  73 + {
  74 + tagid = @"null";
  75 + }
  76 + _imgUrl = nil;
62 77 [self toast:[NSString stringWithFormat:@"错误码:%@,%@\n请求广告位id:%@",errorDic[@"errorCode"],errorDic[@"errorMessage"],tagid]];
63 78 }else
64 79 {
  80 + currentMdl = adModel;
  81 + newsModel = adModel;
  82 + _imgUrl = adModel.nativead.img[0].url;
65 83 [self toast:[NSString stringWithFormat:@"model:%@",adModel]];
66 84 } }];
67 85 }
... ... @@ -75,15 +93,19 @@
75 93 {
76 94 tagid = @"null";
77 95 }
  96 + _imgUrl = nil;
78 97 [self toast:[NSString stringWithFormat:@"错误码:%@,%@\n请求广告位id:%@",errorDic[@"errorCode"],errorDic[@"errorMessage"],tagid]];
79 98 }else
80 99 {
  100 + currentMdl = adModel;
  101 + appWallModel = adModel;
  102 + _imgUrl = adModel.nativead.img[0].url;
81 103 [self toast:[NSString stringWithFormat:@"model:%@",adModel]];
82 104 }
83 105 }];
84 106 }
85 107 break;
86   - case 10002: {//轮播图
  108 + case 10002: {//轮播图 339
87 109 [[VLionManager manager] vl_nativeAdShufflingWithTagId:@"339" handler:^(VLionNativeAdShufflingModel * _Nullable adModel, NSDictionary * _Nullable errorDic) {
88 110 NSLog(@"model:%@",adModel);
89 111 if (errorDic) {
... ... @@ -92,9 +114,13 @@
92 114 {
93 115 tagid = @"null";
94 116 }
  117 + _imgUrl = nil;
95 118 [self toast:[NSString stringWithFormat:@"错误码:%@,%@\n请求广告位id:%@",errorDic[@"errorCode"],errorDic[@"errorMessage"],tagid]];
96 119 }else
97 120 {
  121 + currentMdl = adModel;
  122 + shuModel = adModel;
  123 + _imgUrl = adModel.nativead.img[0].url;
98 124 NSString *string = @"";
99 125 string = [string stringByAppendingString:[NSString stringWithFormat:@"状态码:%d\n",adModel.status]];
100 126 string = [string stringByAppendingString:[NSString stringWithFormat:@"创意类型:%d\n",adModel.adt]];
... ... @@ -138,9 +164,13 @@
138 164 {
139 165 tagid = @"null";
140 166 }
  167 + _imgUrl = nil;
141 168 [self toast:[NSString stringWithFormat:@"错误码:%@,%@\n请求广告位id:%@",errorDic[@"errorCode"],errorDic[@"errorMessage"],tagid]];
142 169 }else
143 170 {
  171 + currentMdl = adModel;
  172 + waterModel = adModel;
  173 + _imgUrl = adModel.nativead.img[0].url;
144 174 [self toast:[NSString stringWithFormat:@"model:%@",adModel]];
145 175 }
146 176 }];
... ... @@ -154,9 +184,13 @@
154 184 {
155 185 tagid = @"null";
156 186 }
  187 + _imgUrl = nil;
157 188 [self toast:[NSString stringWithFormat:@"错误码:%@,%@\n请求广告位id:%@",errorDic[@"errorCode"],errorDic[@"errorMessage"],tagid]];
158 189 }else
159 190 {
  191 + currentMdl = adModel;
  192 + infoModel = adModel;
  193 + _imgUrl = adModel.nativead.img[0].url;
160 194 NSString *string = @"";
161 195 string = [string stringByAppendingString:[NSString stringWithFormat:@"状态码:%d\n",adModel.status]];
162 196 string = [string stringByAppendingString:[NSString stringWithFormat:@"创意类型:%d\n",adModel.adt]];
... ... @@ -209,11 +243,40 @@
209 243 }
210 244 }
211 245  
  246 +//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  247 +//{
  248 +// NSSet *allTouches = [event allTouches]; //返回与当前接收者有关的所有的触摸对象
  249 +// UITouch *touch = [allTouches anyObject]; //视图中的所有对象
  250 +// CGPoint point = [touch locationInView:[touch view]]; //返回触摸点在视图中的当前坐标
  251 +// [[VLionManager manager] clickNativedAdWithModel:shuModel upPoint:point downPoint:point viewController:self adBackBlock:^{
  252 +// NSLog(@"adback");
  253 +// }];
  254 +//}
  255 +
212 256 - (void)closeBtnAction
213 257 {
214 258 [self dismissViewControllerAnimated:YES completion:NULL];
215 259 }
216 260  
  261 +- (void)xuanRanBtnAction
  262 +{
  263 + if (_imgUrl.length == 0 || _imgUrl == nil) {
  264 + [self toast:@"请先获取原生广告数据!"];
  265 + return;
  266 + }
  267 + self.imgView.hidden = NO;
  268 + [self.imgView sd_setImageWithURL:[NSURL URLWithString:_imgUrl] placeholderImage:nil];
  269 +}
  270 +
  271 +- (void)tapAd:(UITapGestureRecognizer *)gesture
  272 +{
  273 + CGPoint point = [gesture locationInView:self.imgView];
  274 + [[VLionManager manager] clickNativedAdWithModel:currentMdl upPoint:point downPoint:point viewController:self adBackBlock:^{
  275 + NSLog(@"adback");
  276 + }];
  277 +}
  278 +
  279 +
217 280 #pragma mark - alertView
218 281 - (void)toast:(NSString *)message
219 282 {
... ... @@ -230,11 +293,37 @@
230 293 });
231 294 }
232 295  
  296 +- (UIImageView *)imgView
  297 +{
  298 + if (!_imgView)
  299 + {
  300 + _imgView = [[UIImageView alloc] initWithFrame:CGRectMake(50, self.closeBtn.bottom + 10, self.view.width - 100, 200)];
  301 + _imgView.hidden = YES;
  302 + _imgView.userInteractionEnabled = YES;
  303 + [_imgView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAd:)]];
  304 + }
  305 + return _imgView;
  306 +}
  307 +
  308 +- (UIButton *)xuanRanBtn
  309 +{
  310 + if (!_xuanRanBtn) {
  311 + _xuanRanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  312 + _xuanRanBtn.frame = CGRectMake(self.view.width - 50, IPHONEX ? 44 : 20, 60, 30);
  313 + [_xuanRanBtn setTitle:@"渲染" forState:UIControlStateNormal];
  314 + [_xuanRanBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
  315 + _xuanRanBtn.center = self.imgView.center;
  316 + _xuanRanBtn.y = H_SPACE+(IPHONEX ? 100 : 120) - 50;
  317 + [_xuanRanBtn addTarget:self action:@selector(xuanRanBtnAction) forControlEvents:UIControlEventTouchUpInside];
  318 + }
  319 + return _xuanRanBtn;
  320 +}
  321 +
233 322 - (UIButton *)closeBtn
234 323 {
235 324 if (!_closeBtn) {
236 325 _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
237   - _closeBtn.frame = CGRectMake(self.view.bounds.size.width - 50, 20, 30, 30);
  326 + _closeBtn.frame = CGRectMake(self.view.width - 50, IPHONEX ? 44 : 20, 30, 30);
238 327 [_closeBtn setImage:[UIImage imageNamed:@"native close"] forState:UIControlStateNormal];
239 328 [_closeBtn addTarget:self action:@selector(closeBtnAction) forControlEvents:UIControlEventTouchUpInside];
240 329 }
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/MKAnnotationView+WebCache.h 0 → 100755
  1 +//
  2 +// MKAnnotationView+WebCache.h
  3 +// SDWebImage
  4 +//
  5 +// Created by Olivier Poitrey on 14/03/12.
  6 +// Copyright (c) 2012 Dailymotion. All rights reserved.
  7 +//
  8 +
  9 +#import "MapKit/MapKit.h"
  10 +#import "SDWebImageManager.h"
  11 +
  12 +/**
  13 + * Integrates SDWebImage async downloading and caching of remote images with MKAnnotationView.
  14 + */
  15 +@interface MKAnnotationView (WebCache)
  16 +
  17 +/**
  18 + * Get the current image URL.
  19 + *
  20 + * Note that because of the limitations of categories this property can get out of sync
  21 + * if you use sd_setImage: directly.
  22 + */
  23 +- (NSURL *)sd_imageURL;
  24 +
  25 +/**
  26 + * Set the imageView `image` with an `url`.
  27 + *
  28 + * The download is asynchronous and cached.
  29 + *
  30 + * @param url The url for the image.
  31 + */
  32 +- (void)sd_setImageWithURL:(NSURL *)url;
  33 +
  34 +/**
  35 + * Set the imageView `image` with an `url` and a placeholder.
  36 + *
  37 + * The download is asynchronous and cached.
  38 + *
  39 + * @param url The url for the image.
  40 + * @param placeholder The image to be set initially, until the image request finishes.
  41 + * @see sd_setImageWithURL:placeholderImage:options:
  42 + */
  43 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
  44 +
  45 +/**
  46 + * Set the imageView `image` with an `url`, placeholder and custom options.
  47 + *
  48 + * The download is asynchronous and cached.
  49 + *
  50 + * @param url The url for the image.
  51 + * @param placeholder The image to be set initially, until the image request finishes.
  52 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  53 + */
  54 +
  55 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
  56 +
  57 +/**
  58 + * Set the imageView `image` with an `url`.
  59 + *
  60 + * The download is asynchronous and cached.
  61 + *
  62 + * @param url The url for the image.
  63 + * @param completedBlock A block called when operation has been completed. This block has no return value
  64 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  65 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  66 + * indicating if the image was retrieved from the local cache or from the network.
  67 + * The fourth parameter is the original image url.
  68 + */
  69 +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
  70 +
  71 +/**
  72 + * Set the imageView `image` with an `url`, placeholder.
  73 + *
  74 + * The download is asynchronous and cached.
  75 + *
  76 + * @param url The url for the image.
  77 + * @param placeholder The image to be set initially, until the image request finishes.
  78 + * @param completedBlock A block called when operation has been completed. This block has no return value
  79 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  80 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  81 + * indicating if the image was retrieved from the local cache or from the network.
  82 + * The fourth parameter is the original image url.
  83 + */
  84 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
  85 +
  86 +/**
  87 + * Set the imageView `image` with an `url`, placeholder and custom options.
  88 + *
  89 + * The download is asynchronous and cached.
  90 + *
  91 + * @param url The url for the image.
  92 + * @param placeholder The image to be set initially, until the image request finishes.
  93 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  94 + * @param completedBlock A block called when operation has been completed. This block has no return value
  95 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  96 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  97 + * indicating if the image was retrieved from the local cache or from the network.
  98 + * The fourth parameter is the original image url.
  99 + */
  100 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
  101 +
  102 +/**
  103 + * Cancel the current download
  104 + */
  105 +- (void)sd_cancelCurrentImageLoad;
  106 +
  107 +@end
  108 +
  109 +
  110 +@interface MKAnnotationView (WebCacheDeprecated)
  111 +
  112 +- (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`");
  113 +
  114 +- (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`");
  115 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`");
  116 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:`");
  117 +
  118 +- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`");
  119 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`");
  120 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`");
  121 +
  122 +- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`");
  123 +
  124 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/MKAnnotationView+WebCache.m 0 → 100755
  1 +//
  2 +// MKAnnotationView+WebCache.m
  3 +// SDWebImage
  4 +//
  5 +// Created by Olivier Poitrey on 14/03/12.
  6 +// Copyright (c) 2012 Dailymotion. All rights reserved.
  7 +//
  8 +
  9 +#import "MKAnnotationView+WebCache.h"
  10 +#import "objc/runtime.h"
  11 +#import "UIView+WebCacheOperation.h"
  12 +
  13 +static char imageURLKey;
  14 +
  15 +@implementation MKAnnotationView (WebCache)
  16 +
  17 +- (NSURL *)sd_imageURL {
  18 + return objc_getAssociatedObject(self, &imageURLKey);
  19 +}
  20 +
  21 +- (void)sd_setImageWithURL:(NSURL *)url {
  22 + [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil];
  23 +}
  24 +
  25 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
  26 + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
  27 +}
  28 +
  29 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
  30 + [self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
  31 +}
  32 +
  33 +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
  34 + [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:completedBlock];
  35 +}
  36 +
  37 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
  38 + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:completedBlock];
  39 +}
  40 +
  41 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
  42 + [self sd_cancelCurrentImageLoad];
  43 +
  44 + objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  45 + self.image = placeholder;
  46 +
  47 + if (url) {
  48 + __weak __typeof(self)wself = self;
  49 + id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
  50 + if (!wself) return;
  51 + dispatch_main_sync_safe(^{
  52 + __strong MKAnnotationView *sself = wself;
  53 + if (!sself) return;
  54 + if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) {
  55 + completedBlock(image, error, cacheType, url);
  56 + return;
  57 + } else if (image) {
  58 + wself.image = image;
  59 + [wself setNeedsLayout];
  60 + } else {
  61 + if ((options & SDWebImageDelayPlaceholder)) {
  62 + wself.image = placeholder;
  63 + [wself setNeedsLayout];
  64 + }
  65 + }
  66 + if (completedBlock && finished) {
  67 + completedBlock(image, error, cacheType, url);
  68 + }
  69 + });
  70 + }];
  71 + [self sd_setImageLoadOperation:operation forKey:@"MKAnnotationViewImage"];
  72 + } else {
  73 + dispatch_main_async_safe(^{
  74 + NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
  75 + if (completedBlock) {
  76 + completedBlock(nil, error, SDImageCacheTypeNone, url);
  77 + }
  78 + });
  79 + }
  80 +}
  81 +
  82 +- (void)sd_cancelCurrentImageLoad {
  83 + [self sd_cancelImageLoadOperationWithKey:@"MKAnnotationViewImage"];
  84 +}
  85 +
  86 +@end
  87 +
  88 +
  89 +@implementation MKAnnotationView (WebCacheDeprecated)
  90 +
  91 +- (NSURL *)imageURL {
  92 + return [self sd_imageURL];
  93 +}
  94 +
  95 +- (void)setImageWithURL:(NSURL *)url {
  96 + [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil];
  97 +}
  98 +
  99 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
  100 + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
  101 +}
  102 +
  103 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
  104 + [self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
  105 +}
  106 +
  107 +- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
  108 + [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  109 + if (completedBlock) {
  110 + completedBlock(image, error, cacheType);
  111 + }
  112 + }];
  113 +}
  114 +
  115 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
  116 + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  117 + if (completedBlock) {
  118 + completedBlock(image, error, cacheType);
  119 + }
  120 + }];
  121 +}
  122 +
  123 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
  124 + [self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  125 + if (completedBlock) {
  126 + completedBlock(image, error, cacheType);
  127 + }
  128 + }];
  129 +}
  130 +
  131 +- (void)cancelCurrentImageLoad {
  132 + [self sd_cancelCurrentImageLoad];
  133 +}
  134 +
  135 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/NSData+ImageContentType.h 0 → 100755
  1 +//
  2 +// Created by Fabrice Aneche on 06/01/14.
  3 +// Copyright (c) 2014 Dailymotion. All rights reserved.
  4 +//
  5 +
  6 +#import <Foundation/Foundation.h>
  7 +
  8 +@interface NSData (ImageContentType)
  9 +
  10 +/**
  11 + * Compute the content type for an image data
  12 + *
  13 + * @param data the input data
  14 + *
  15 + * @return the content type as string (i.e. image/jpeg, image/gif)
  16 + */
  17 ++ (NSString *)sd_contentTypeForImageData:(NSData *)data;
  18 +
  19 +@end
  20 +
  21 +
  22 +@interface NSData (ImageContentTypeDeprecated)
  23 +
  24 ++ (NSString *)contentTypeForImageData:(NSData *)data __deprecated_msg("Use `sd_contentTypeForImageData:`");
  25 +
  26 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/NSData+ImageContentType.m 0 → 100755
  1 +//
  2 +// Created by Fabrice Aneche on 06/01/14.
  3 +// Copyright (c) 2014 Dailymotion. All rights reserved.
  4 +//
  5 +
  6 +#import "NSData+ImageContentType.h"
  7 +
  8 +
  9 +@implementation NSData (ImageContentType)
  10 +
  11 ++ (NSString *)sd_contentTypeForImageData:(NSData *)data {
  12 + uint8_t c;
  13 + [data getBytes:&c length:1];
  14 + switch (c) {
  15 + case 0xFF:
  16 + return @"image/jpeg";
  17 + case 0x89:
  18 + return @"image/png";
  19 + case 0x47:
  20 + return @"image/gif";
  21 + case 0x49:
  22 + case 0x4D:
  23 + return @"image/tiff";
  24 + case 0x52:
  25 + // R as RIFF for WEBP
  26 + if ([data length] < 12) {
  27 + return nil;
  28 + }
  29 +
  30 + NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
  31 + if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) {
  32 + return @"image/webp";
  33 + }
  34 +
  35 + return nil;
  36 + }
  37 + return nil;
  38 +}
  39 +
  40 +@end
  41 +
  42 +
  43 +@implementation NSData (ImageContentTypeDeprecated)
  44 +
  45 ++ (NSString *)contentTypeForImageData:(NSData *)data {
  46 + return [self sd_contentTypeForImageData:data];
  47 +}
  48 +
  49 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/SDImageCache.h 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "SDWebImageCompat.h"
  11 +
  12 +typedef NS_ENUM(NSInteger, SDImageCacheType) {
  13 + /**
  14 + * The image wasn't available the SDWebImage caches, but was downloaded from the web.
  15 + */
  16 + SDImageCacheTypeNone,
  17 + /**
  18 + * The image was obtained from the disk cache.
  19 + */
  20 + SDImageCacheTypeDisk,
  21 + /**
  22 + * The image was obtained from the memory cache.
  23 + */
  24 + SDImageCacheTypeMemory
  25 +};
  26 +
  27 +typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType cacheType);
  28 +
  29 +typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache);
  30 +
  31 +typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger totalSize);
  32 +
  33 +/**
  34 + * SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed
  35 + * asynchronous so it doesn’t add unnecessary latency to the UI.
  36 + */
  37 +@interface SDImageCache : NSObject
  38 +
  39 +/**
  40 + * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory.
  41 + * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption.
  42 + */
  43 +@property (assign, nonatomic) BOOL shouldDecompressImages;
  44 +
  45 +/**
  46 + * disable iCloud backup [defaults to YES]
  47 + */
  48 +@property (assign, nonatomic) BOOL shouldDisableiCloud;
  49 +
  50 +/**
  51 + * use memory cache [defaults to YES]
  52 + */
  53 +@property (assign, nonatomic) BOOL shouldCacheImagesInMemory;
  54 +
  55 +/**
  56 + * The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory.
  57 + */
  58 +@property (assign, nonatomic) NSUInteger maxMemoryCost;
  59 +
  60 +/**
  61 + * The maximum number of objects the cache should hold.
  62 + */
  63 +@property (assign, nonatomic) NSUInteger maxMemoryCountLimit;
  64 +
  65 +/**
  66 + * The maximum length of time to keep an image in the cache, in seconds
  67 + */
  68 +@property (assign, nonatomic) NSInteger maxCacheAge;
  69 +
  70 +/**
  71 + * The maximum size of the cache, in bytes.
  72 + */
  73 +@property (assign, nonatomic) NSUInteger maxCacheSize;
  74 +
  75 +/**
  76 + * Returns global shared cache instance
  77 + *
  78 + * @return SDImageCache global instance
  79 + */
  80 ++ (SDImageCache *)sharedImageCache;
  81 +
  82 +/**
  83 + * Init a new cache store with a specific namespace
  84 + *
  85 + * @param ns The namespace to use for this cache store
  86 + */
  87 +- (id)initWithNamespace:(NSString *)ns;
  88 +
  89 +/**
  90 + * Init a new cache store with a specific namespace and directory
  91 + *
  92 + * @param ns The namespace to use for this cache store
  93 + * @param directory Directory to cache disk images in
  94 + */
  95 +- (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory;
  96 +
  97 +-(NSString *)makeDiskCachePath:(NSString*)fullNamespace;
  98 +
  99 +/**
  100 + * Add a read-only cache path to search for images pre-cached by SDImageCache
  101 + * Useful if you want to bundle pre-loaded images with your app
  102 + *
  103 + * @param path The path to use for this read-only cache path
  104 + */
  105 +- (void)addReadOnlyCachePath:(NSString *)path;
  106 +
  107 +/**
  108 + * Store an image into memory and disk cache at the given key.
  109 + *
  110 + * @param image The image to store
  111 + * @param key The unique image cache key, usually it's image absolute URL
  112 + */
  113 +- (void)storeImage:(UIImage *)image forKey:(NSString *)key;
  114 +
  115 +/**
  116 + * Store an image into memory and optionally disk cache at the given key.
  117 + *
  118 + * @param image The image to store
  119 + * @param key The unique image cache key, usually it's image absolute URL
  120 + * @param toDisk Store the image to disk cache if YES
  121 + */
  122 +- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk;
  123 +
  124 +/**
  125 + * Store an image into memory and optionally disk cache at the given key.
  126 + *
  127 + * @param image The image to store
  128 + * @param recalculate BOOL indicates if imageData can be used or a new data should be constructed from the UIImage
  129 + * @param imageData The image data as returned by the server, this representation will be used for disk storage
  130 + * instead of converting the given image object into a storable/compressed image format in order
  131 + * to save quality and CPU
  132 + * @param key The unique image cache key, usually it's image absolute URL
  133 + * @param toDisk Store the image to disk cache if YES
  134 + */
  135 +- (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk;
  136 +
  137 +/**
  138 + * Store image NSData into disk cache at the given key.
  139 + *
  140 + * @param imageData The image data to store
  141 + * @param key The unique image cache key, usually it's image absolute URL
  142 + */
  143 +- (void)storeImageDataToDisk:(NSData *)imageData forKey:(NSString *)key;
  144 +
  145 +/**
  146 + * Query the disk cache asynchronously.
  147 + *
  148 + * @param key The unique key used to store the wanted image
  149 + */
  150 +- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock;
  151 +
  152 +/**
  153 + * Query the memory cache synchronously.
  154 + *
  155 + * @param key The unique key used to store the wanted image
  156 + */
  157 +- (UIImage *)imageFromMemoryCacheForKey:(NSString *)key;
  158 +
  159 +/**
  160 + * Query the disk cache synchronously after checking the memory cache.
  161 + *
  162 + * @param key The unique key used to store the wanted image
  163 + */
  164 +- (UIImage *)imageFromDiskCacheForKey:(NSString *)key;
  165 +
  166 +/**
  167 + * Remove the image from memory and disk cache asynchronously
  168 + *
  169 + * @param key The unique image cache key
  170 + */
  171 +- (void)removeImageForKey:(NSString *)key;
  172 +
  173 +
  174 +/**
  175 + * Remove the image from memory and disk cache asynchronously
  176 + *
  177 + * @param key The unique image cache key
  178 + * @param completion An block that should be executed after the image has been removed (optional)
  179 + */
  180 +- (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion;
  181 +
  182 +/**
  183 + * Remove the image from memory and optionally disk cache asynchronously
  184 + *
  185 + * @param key The unique image cache key
  186 + * @param fromDisk Also remove cache entry from disk if YES
  187 + */
  188 +- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk;
  189 +
  190 +/**
  191 + * Remove the image from memory and optionally disk cache asynchronously
  192 + *
  193 + * @param key The unique image cache key
  194 + * @param fromDisk Also remove cache entry from disk if YES
  195 + * @param completion An block that should be executed after the image has been removed (optional)
  196 + */
  197 +- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion;
  198 +
  199 +/**
  200 + * Clear all memory cached images
  201 + */
  202 +- (void)clearMemory;
  203 +
  204 +/**
  205 + * Clear all disk cached images. Non-blocking method - returns immediately.
  206 + * @param completion An block that should be executed after cache expiration completes (optional)
  207 + */
  208 +- (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion;
  209 +
  210 +/**
  211 + * Clear all disk cached images
  212 + * @see clearDiskOnCompletion:
  213 + */
  214 +- (void)clearDisk;
  215 +
  216 +/**
  217 + * Remove all expired cached image from disk. Non-blocking method - returns immediately.
  218 + * @param completionBlock An block that should be executed after cache expiration completes (optional)
  219 + */
  220 +- (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock;
  221 +
  222 +/**
  223 + * Remove all expired cached image from disk
  224 + * @see cleanDiskWithCompletionBlock:
  225 + */
  226 +- (void)cleanDisk;
  227 +
  228 +/**
  229 + * Get the size used by the disk cache
  230 + */
  231 +- (NSUInteger)getSize;
  232 +
  233 +/**
  234 + * Get the number of images in the disk cache
  235 + */
  236 +- (NSUInteger)getDiskCount;
  237 +
  238 +/**
  239 + * Asynchronously calculate the disk cache's size.
  240 + */
  241 +- (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock;
  242 +
  243 +/**
  244 + * Async check if image exists in disk cache already (does not load the image)
  245 + *
  246 + * @param key the key describing the url
  247 + * @param completionBlock the block to be executed when the check is done.
  248 + * @note the completion block will be always executed on the main queue
  249 + */
  250 +- (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;
  251 +
  252 +/**
  253 + * Check if image exists in disk cache already (does not load the image)
  254 + *
  255 + * @param key the key describing the url
  256 + *
  257 + * @return YES if an image exists for the given key
  258 + */
  259 +- (BOOL)diskImageExistsWithKey:(NSString *)key;
  260 +
  261 +/**
  262 + * Get the cache path for a certain key (needs the cache path root folder)
  263 + *
  264 + * @param key the key (can be obtained from url using cacheKeyForURL)
  265 + * @param path the cache path root folder
  266 + *
  267 + * @return the cache path
  268 + */
  269 +- (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path;
  270 +
  271 +/**
  272 + * Get the default cache path for a certain key
  273 + *
  274 + * @param key the key (can be obtained from url using cacheKeyForURL)
  275 + *
  276 + * @return the default cache path
  277 + */
  278 +- (NSString *)defaultCachePathForKey:(NSString *)key;
  279 +
  280 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/SDImageCache.m 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import "SDImageCache.h"
  10 +#import "SDWebImageDecoder.h"
  11 +#import "UIImage+MultiFormat.h"
  12 +#import <CommonCrypto/CommonDigest.h>
  13 +
  14 +// See https://github.com/rs/SDWebImage/pull/1141 for discussion
  15 +@interface AutoPurgeCache : NSCache
  16 +@end
  17 +
  18 +@implementation AutoPurgeCache
  19 +
  20 +- (id)init
  21 +{
  22 + self = [super init];
  23 + if (self) {
  24 + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeAllObjects) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
  25 + }
  26 + return self;
  27 +}
  28 +
  29 +- (void)dealloc
  30 +{
  31 + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
  32 +
  33 +}
  34 +
  35 +@end
  36 +
  37 +static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
  38 +// PNG signature bytes and data (below)
  39 +static unsigned char kPNGSignatureBytes[8] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
  40 +static NSData *kPNGSignatureData = nil;
  41 +
  42 +BOOL ImageDataHasPNGPreffix(NSData *data);
  43 +
  44 +BOOL ImageDataHasPNGPreffix(NSData *data) {
  45 + NSUInteger pngSignatureLength = [kPNGSignatureData length];
  46 + if ([data length] >= pngSignatureLength) {
  47 + if ([[data subdataWithRange:NSMakeRange(0, pngSignatureLength)] isEqualToData:kPNGSignatureData]) {
  48 + return YES;
  49 + }
  50 + }
  51 +
  52 + return NO;
  53 +}
  54 +
  55 +FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
  56 + return image.size.height * image.size.width * image.scale * image.scale;
  57 +}
  58 +
  59 +@interface SDImageCache ()
  60 +
  61 +@property (strong, nonatomic) NSCache *memCache;
  62 +@property (strong, nonatomic) NSString *diskCachePath;
  63 +@property (strong, nonatomic) NSMutableArray *customPaths;
  64 +@property (SDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t ioQueue;
  65 +
  66 +@end
  67 +
  68 +
  69 +@implementation SDImageCache {
  70 + NSFileManager *_fileManager;
  71 +}
  72 +
  73 ++ (SDImageCache *)sharedImageCache {
  74 + static dispatch_once_t once;
  75 + static id instance;
  76 + dispatch_once(&once, ^{
  77 + instance = [self new];
  78 + });
  79 + return instance;
  80 +}
  81 +
  82 +- (id)init {
  83 + return [self initWithNamespace:@"default"];
  84 +}
  85 +
  86 +- (id)initWithNamespace:(NSString *)ns {
  87 + NSString *path = [self makeDiskCachePath:ns];
  88 + return [self initWithNamespace:ns diskCacheDirectory:path];
  89 +}
  90 +
  91 +- (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory {
  92 + if ((self = [super init])) {
  93 + NSString *fullNamespace = [@"com.hackemist.SDWebImageCache." stringByAppendingString:ns];
  94 +
  95 + // initialise PNG signature data
  96 + kPNGSignatureData = [NSData dataWithBytes:kPNGSignatureBytes length:8];
  97 +
  98 + // Create IO serial queue
  99 + _ioQueue = dispatch_queue_create("com.hackemist.SDWebImageCache", DISPATCH_QUEUE_SERIAL);
  100 +
  101 + // Init default values
  102 + _maxCacheAge = kDefaultCacheMaxCacheAge;
  103 +
  104 + // Init the memory cache
  105 + _memCache = [[AutoPurgeCache alloc] init];
  106 + _memCache.name = fullNamespace;
  107 +
  108 + // Init the disk cache
  109 + if (directory != nil) {
  110 + _diskCachePath = [directory stringByAppendingPathComponent:fullNamespace];
  111 + } else {
  112 + NSString *path = [self makeDiskCachePath:ns];
  113 + _diskCachePath = path;
  114 + }
  115 +
  116 + // Set decompression to YES
  117 + _shouldDecompressImages = YES;
  118 +
  119 + // memory cache enabled
  120 + _shouldCacheImagesInMemory = YES;
  121 +
  122 + // Disable iCloud
  123 + _shouldDisableiCloud = YES;
  124 +
  125 + dispatch_sync(_ioQueue, ^{
  126 + _fileManager = [NSFileManager new];
  127 + });
  128 +
  129 +#if TARGET_OS_IOS
  130 + // Subscribe to app events
  131 + [[NSNotificationCenter defaultCenter] addObserver:self
  132 + selector:@selector(clearMemory)
  133 + name:UIApplicationDidReceiveMemoryWarningNotification
  134 + object:nil];
  135 +
  136 + [[NSNotificationCenter defaultCenter] addObserver:self
  137 + selector:@selector(cleanDisk)
  138 + name:UIApplicationWillTerminateNotification
  139 + object:nil];
  140 +
  141 + [[NSNotificationCenter defaultCenter] addObserver:self
  142 + selector:@selector(backgroundCleanDisk)
  143 + name:UIApplicationDidEnterBackgroundNotification
  144 + object:nil];
  145 +#endif
  146 + }
  147 +
  148 + return self;
  149 +}
  150 +
  151 +- (void)dealloc {
  152 + [[NSNotificationCenter defaultCenter] removeObserver:self];
  153 + SDDispatchQueueRelease(_ioQueue);
  154 +}
  155 +
  156 +- (void)addReadOnlyCachePath:(NSString *)path {
  157 + if (!self.customPaths) {
  158 + self.customPaths = [NSMutableArray new];
  159 + }
  160 +
  161 + if (![self.customPaths containsObject:path]) {
  162 + [self.customPaths addObject:path];
  163 + }
  164 +}
  165 +
  166 +- (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path {
  167 + NSString *filename = [self cachedFileNameForKey:key];
  168 + return [path stringByAppendingPathComponent:filename];
  169 +}
  170 +
  171 +- (NSString *)defaultCachePathForKey:(NSString *)key {
  172 + return [self cachePathForKey:key inPath:self.diskCachePath];
  173 +}
  174 +
  175 +#pragma mark SDImageCache (private)
  176 +
  177 +- (NSString *)cachedFileNameForKey:(NSString *)key {
  178 + const char *str = [key UTF8String];
  179 + if (str == NULL) {
  180 + str = "";
  181 + }
  182 + unsigned char r[CC_MD5_DIGEST_LENGTH];
  183 + CC_MD5(str, (CC_LONG)strlen(str), r);
  184 + NSString *filename = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%@",
  185 + r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10],
  186 + r[11], r[12], r[13], r[14], r[15], [[key pathExtension] isEqualToString:@""] ? @"" : [NSString stringWithFormat:@".%@", [key pathExtension]]];
  187 +
  188 + return filename;
  189 +}
  190 +
  191 +#pragma mark ImageCache
  192 +
  193 +// Init the disk cache
  194 +-(NSString *)makeDiskCachePath:(NSString*)fullNamespace{
  195 + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  196 + return [paths[0] stringByAppendingPathComponent:fullNamespace];
  197 +}
  198 +
  199 +- (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk {
  200 + if (!image || !key) {
  201 + return;
  202 + }
  203 + // if memory cache is enabled
  204 + if (self.shouldCacheImagesInMemory) {
  205 + NSUInteger cost = SDCacheCostForImage(image);
  206 + [self.memCache setObject:image forKey:key cost:cost];
  207 + }
  208 +
  209 + if (toDisk) {
  210 + dispatch_async(self.ioQueue, ^{
  211 + NSData *data = imageData;
  212 +
  213 + if (image && (recalculate || !data)) {
  214 +#if TARGET_OS_IPHONE
  215 + // We need to determine if the image is a PNG or a JPEG
  216 + // PNGs are easier to detect because they have a unique signature (http://www.w3.org/TR/PNG-Structure.html)
  217 + // The first eight bytes of a PNG file always contain the following (decimal) values:
  218 + // 137 80 78 71 13 10 26 10
  219 +
  220 + // If the imageData is nil (i.e. if trying to save a UIImage directly or the image was transformed on download)
  221 + // and the image has an alpha channel, we will consider it PNG to avoid losing the transparency
  222 + int alphaInfo = CGImageGetAlphaInfo(image.CGImage);
  223 + BOOL hasAlpha = !(alphaInfo == kCGImageAlphaNone ||
  224 + alphaInfo == kCGImageAlphaNoneSkipFirst ||
  225 + alphaInfo == kCGImageAlphaNoneSkipLast);
  226 + BOOL imageIsPng = hasAlpha;
  227 +
  228 + // But if we have an image data, we will look at the preffix
  229 + if ([imageData length] >= [kPNGSignatureData length]) {
  230 + imageIsPng = ImageDataHasPNGPreffix(imageData);
  231 + }
  232 +
  233 + if (imageIsPng) {
  234 + data = UIImagePNGRepresentation(image);
  235 + }
  236 + else {
  237 + data = UIImageJPEGRepresentation(image, (CGFloat)1.0);
  238 + }
  239 +#else
  240 + data = [NSBitmapImageRep representationOfImageRepsInArray:image.representations usingType: NSJPEGFileType properties:nil];
  241 +#endif
  242 + }
  243 +
  244 + [self storeImageDataToDisk:data forKey:key];
  245 + });
  246 + }
  247 +}
  248 +
  249 +- (void)storeImage:(UIImage *)image forKey:(NSString *)key {
  250 + [self storeImage:image recalculateFromImage:YES imageData:nil forKey:key toDisk:YES];
  251 +}
  252 +
  253 +- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk {
  254 + [self storeImage:image recalculateFromImage:YES imageData:nil forKey:key toDisk:toDisk];
  255 +}
  256 +
  257 +- (void)storeImageDataToDisk:(NSData *)imageData forKey:(NSString *)key {
  258 +
  259 + if (!imageData) {
  260 + return;
  261 + }
  262 +
  263 + if (![_fileManager fileExistsAtPath:_diskCachePath]) {
  264 + [_fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL];
  265 + }
  266 +
  267 + // get cache Path for image key
  268 + NSString *cachePathForKey = [self defaultCachePathForKey:key];
  269 + // transform to NSUrl
  270 + NSURL *fileURL = [NSURL fileURLWithPath:cachePathForKey];
  271 +
  272 + [_fileManager createFileAtPath:cachePathForKey contents:imageData attributes:nil];
  273 +
  274 + // disable iCloud backup
  275 + if (self.shouldDisableiCloud) {
  276 + [fileURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
  277 + }
  278 +}
  279 +
  280 +- (BOOL)diskImageExistsWithKey:(NSString *)key {
  281 + BOOL exists = NO;
  282 +
  283 + // this is an exception to access the filemanager on another queue than ioQueue, but we are using the shared instance
  284 + // from apple docs on NSFileManager: The methods of the shared NSFileManager object can be called from multiple threads safely.
  285 + exists = [[NSFileManager defaultManager] fileExistsAtPath:[self defaultCachePathForKey:key]];
  286 +
  287 + // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
  288 + // checking the key with and without the extension
  289 + if (!exists) {
  290 + exists = [[NSFileManager defaultManager] fileExistsAtPath:[[self defaultCachePathForKey:key] stringByDeletingPathExtension]];
  291 + }
  292 +
  293 + return exists;
  294 +}
  295 +
  296 +- (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock {
  297 + dispatch_async(_ioQueue, ^{
  298 + BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]];
  299 +
  300 + // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
  301 + // checking the key with and without the extension
  302 + if (!exists) {
  303 + exists = [_fileManager fileExistsAtPath:[[self defaultCachePathForKey:key] stringByDeletingPathExtension]];
  304 + }
  305 +
  306 + if (completionBlock) {
  307 + dispatch_async(dispatch_get_main_queue(), ^{
  308 + completionBlock(exists);
  309 + });
  310 + }
  311 + });
  312 +}
  313 +
  314 +- (UIImage *)imageFromMemoryCacheForKey:(NSString *)key {
  315 + return [self.memCache objectForKey:key];
  316 +}
  317 +
  318 +- (UIImage *)imageFromDiskCacheForKey:(NSString *)key {
  319 +
  320 + // First check the in-memory cache...
  321 + UIImage *image = [self imageFromMemoryCacheForKey:key];
  322 + if (image) {
  323 + return image;
  324 + }
  325 +
  326 + // Second check the disk cache...
  327 + UIImage *diskImage = [self diskImageForKey:key];
  328 + if (diskImage && self.shouldCacheImagesInMemory) {
  329 + NSUInteger cost = SDCacheCostForImage(diskImage);
  330 + [self.memCache setObject:diskImage forKey:key cost:cost];
  331 + }
  332 +
  333 + return diskImage;
  334 +}
  335 +
  336 +- (NSData *)diskImageDataBySearchingAllPathsForKey:(NSString *)key {
  337 + NSString *defaultPath = [self defaultCachePathForKey:key];
  338 + NSData *data = [NSData dataWithContentsOfFile:defaultPath];
  339 + if (data) {
  340 + return data;
  341 + }
  342 +
  343 + // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
  344 + // checking the key with and without the extension
  345 + data = [NSData dataWithContentsOfFile:[defaultPath stringByDeletingPathExtension]];
  346 + if (data) {
  347 + return data;
  348 + }
  349 +
  350 + NSArray *customPaths = [self.customPaths copy];
  351 + for (NSString *path in customPaths) {
  352 + NSString *filePath = [self cachePathForKey:key inPath:path];
  353 + NSData *imageData = [NSData dataWithContentsOfFile:filePath];
  354 + if (imageData) {
  355 + return imageData;
  356 + }
  357 +
  358 + // fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
  359 + // checking the key with and without the extension
  360 + imageData = [NSData dataWithContentsOfFile:[filePath stringByDeletingPathExtension]];
  361 + if (imageData) {
  362 + return imageData;
  363 + }
  364 + }
  365 +
  366 + return nil;
  367 +}
  368 +
  369 +- (UIImage *)diskImageForKey:(NSString *)key {
  370 + NSData *data = [self diskImageDataBySearchingAllPathsForKey:key];
  371 + if (data) {
  372 + UIImage *image = [UIImage sd_imageWithData:data];
  373 + image = [self scaledImageForKey:key image:image];
  374 + if (self.shouldDecompressImages) {
  375 + image = [UIImage decodedImageWithImage:image];
  376 + }
  377 + return image;
  378 + }
  379 + else {
  380 + return nil;
  381 + }
  382 +}
  383 +
  384 +- (UIImage *)scaledImageForKey:(NSString *)key image:(UIImage *)image {
  385 + return SDScaledImageForKey(key, image);
  386 +}
  387 +
  388 +- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock {
  389 + if (!doneBlock) {
  390 + return nil;
  391 + }
  392 +
  393 + if (!key) {
  394 + doneBlock(nil, SDImageCacheTypeNone);
  395 + return nil;
  396 + }
  397 +
  398 + // First check the in-memory cache...
  399 + UIImage *image = [self imageFromMemoryCacheForKey:key];
  400 + if (image) {
  401 + doneBlock(image, SDImageCacheTypeMemory);
  402 + return nil;
  403 + }
  404 +
  405 + NSOperation *operation = [NSOperation new];
  406 + dispatch_async(self.ioQueue, ^{
  407 + if (operation.isCancelled) {
  408 + return;
  409 + }
  410 +
  411 + @autoreleasepool {
  412 + UIImage *diskImage = [self diskImageForKey:key];
  413 + if (diskImage && self.shouldCacheImagesInMemory) {
  414 + NSUInteger cost = SDCacheCostForImage(diskImage);
  415 + [self.memCache setObject:diskImage forKey:key cost:cost];
  416 + }
  417 +
  418 + dispatch_async(dispatch_get_main_queue(), ^{
  419 + doneBlock(diskImage, SDImageCacheTypeDisk);
  420 + });
  421 + }
  422 + });
  423 +
  424 + return operation;
  425 +}
  426 +
  427 +- (void)removeImageForKey:(NSString *)key {
  428 + [self removeImageForKey:key withCompletion:nil];
  429 +}
  430 +
  431 +- (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion {
  432 + [self removeImageForKey:key fromDisk:YES withCompletion:completion];
  433 +}
  434 +
  435 +- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk {
  436 + [self removeImageForKey:key fromDisk:fromDisk withCompletion:nil];
  437 +}
  438 +
  439 +- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion {
  440 +
  441 + if (key == nil) {
  442 + return;
  443 + }
  444 +
  445 + if (self.shouldCacheImagesInMemory) {
  446 + [self.memCache removeObjectForKey:key];
  447 + }
  448 +
  449 + if (fromDisk) {
  450 + dispatch_async(self.ioQueue, ^{
  451 + [_fileManager removeItemAtPath:[self defaultCachePathForKey:key] error:nil];
  452 +
  453 + if (completion) {
  454 + dispatch_async(dispatch_get_main_queue(), ^{
  455 + completion();
  456 + });
  457 + }
  458 + });
  459 + } else if (completion){
  460 + completion();
  461 + }
  462 +
  463 +}
  464 +
  465 +- (void)setMaxMemoryCost:(NSUInteger)maxMemoryCost {
  466 + self.memCache.totalCostLimit = maxMemoryCost;
  467 +}
  468 +
  469 +- (NSUInteger)maxMemoryCost {
  470 + return self.memCache.totalCostLimit;
  471 +}
  472 +
  473 +- (NSUInteger)maxMemoryCountLimit {
  474 + return self.memCache.countLimit;
  475 +}
  476 +
  477 +- (void)setMaxMemoryCountLimit:(NSUInteger)maxCountLimit {
  478 + self.memCache.countLimit = maxCountLimit;
  479 +}
  480 +
  481 +- (void)clearMemory {
  482 + [self.memCache removeAllObjects];
  483 +}
  484 +
  485 +- (void)clearDisk {
  486 + [self clearDiskOnCompletion:nil];
  487 +}
  488 +
  489 +- (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion
  490 +{
  491 + dispatch_async(self.ioQueue, ^{
  492 + [_fileManager removeItemAtPath:self.diskCachePath error:nil];
  493 + [_fileManager createDirectoryAtPath:self.diskCachePath
  494 + withIntermediateDirectories:YES
  495 + attributes:nil
  496 + error:NULL];
  497 +
  498 + if (completion) {
  499 + dispatch_async(dispatch_get_main_queue(), ^{
  500 + completion();
  501 + });
  502 + }
  503 + });
  504 +}
  505 +
  506 +- (void)cleanDisk {
  507 + [self cleanDiskWithCompletionBlock:nil];
  508 +}
  509 +
  510 +- (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock {
  511 + dispatch_async(self.ioQueue, ^{
  512 + NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES];
  513 + NSArray *resourceKeys = @[NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey];
  514 +
  515 + // This enumerator prefetches useful properties for our cache files.
  516 + NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtURL:diskCacheURL
  517 + includingPropertiesForKeys:resourceKeys
  518 + options:NSDirectoryEnumerationSkipsHiddenFiles
  519 + errorHandler:NULL];
  520 +
  521 + NSDate *expirationDate = [NSDate dateWithTimeIntervalSinceNow:-self.maxCacheAge];
  522 + NSMutableDictionary *cacheFiles = [NSMutableDictionary dictionary];
  523 + NSUInteger currentCacheSize = 0;
  524 +
  525 + // Enumerate all of the files in the cache directory. This loop has two purposes:
  526 + //
  527 + // 1. Removing files that are older than the expiration date.
  528 + // 2. Storing file attributes for the size-based cleanup pass.
  529 + NSMutableArray *urlsToDelete = [[NSMutableArray alloc] init];
  530 + for (NSURL *fileURL in fileEnumerator) {
  531 + NSDictionary *resourceValues = [fileURL resourceValuesForKeys:resourceKeys error:NULL];
  532 +
  533 + // Skip directories.
  534 + if ([resourceValues[NSURLIsDirectoryKey] boolValue]) {
  535 + continue;
  536 + }
  537 +
  538 + // Remove files that are older than the expiration date;
  539 + NSDate *modificationDate = resourceValues[NSURLContentModificationDateKey];
  540 + if ([[modificationDate laterDate:expirationDate] isEqualToDate:expirationDate]) {
  541 + [urlsToDelete addObject:fileURL];
  542 + continue;
  543 + }
  544 +
  545 + // Store a reference to this file and account for its total size.
  546 + NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey];
  547 + currentCacheSize += [totalAllocatedSize unsignedIntegerValue];
  548 + [cacheFiles setObject:resourceValues forKey:fileURL];
  549 + }
  550 +
  551 + for (NSURL *fileURL in urlsToDelete) {
  552 + [_fileManager removeItemAtURL:fileURL error:nil];
  553 + }
  554 +
  555 + // If our remaining disk cache exceeds a configured maximum size, perform a second
  556 + // size-based cleanup pass. We delete the oldest files first.
  557 + if (self.maxCacheSize > 0 && currentCacheSize > self.maxCacheSize) {
  558 + // Target half of our maximum cache size for this cleanup pass.
  559 + const NSUInteger desiredCacheSize = self.maxCacheSize / 2;
  560 +
  561 + // Sort the remaining cache files by their last modification time (oldest first).
  562 + NSArray *sortedFiles = [cacheFiles keysSortedByValueWithOptions:NSSortConcurrent
  563 + usingComparator:^NSComparisonResult(id obj1, id obj2) {
  564 + return [obj1[NSURLContentModificationDateKey] compare:obj2[NSURLContentModificationDateKey]];
  565 + }];
  566 +
  567 + // Delete files until we fall below our desired cache size.
  568 + for (NSURL *fileURL in sortedFiles) {
  569 + if ([_fileManager removeItemAtURL:fileURL error:nil]) {
  570 + NSDictionary *resourceValues = cacheFiles[fileURL];
  571 + NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey];
  572 + currentCacheSize -= [totalAllocatedSize unsignedIntegerValue];
  573 +
  574 + if (currentCacheSize < desiredCacheSize) {
  575 + break;
  576 + }
  577 + }
  578 + }
  579 + }
  580 + if (completionBlock) {
  581 + dispatch_async(dispatch_get_main_queue(), ^{
  582 + completionBlock();
  583 + });
  584 + }
  585 + });
  586 +}
  587 +
  588 +- (void)backgroundCleanDisk {
  589 + Class UIApplicationClass = NSClassFromString(@"UIApplication");
  590 + if(!UIApplicationClass || ![UIApplicationClass respondsToSelector:@selector(sharedApplication)]) {
  591 + return;
  592 + }
  593 + UIApplication *application = [UIApplication performSelector:@selector(sharedApplication)];
  594 + __block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
  595 + // Clean up any unfinished task business by marking where you
  596 + // stopped or ending the task outright.
  597 + [application endBackgroundTask:bgTask];
  598 + bgTask = UIBackgroundTaskInvalid;
  599 + }];
  600 +
  601 + // Start the long-running task and return immediately.
  602 + [self cleanDiskWithCompletionBlock:^{
  603 + [application endBackgroundTask:bgTask];
  604 + bgTask = UIBackgroundTaskInvalid;
  605 + }];
  606 +}
  607 +
  608 +- (NSUInteger)getSize {
  609 + __block NSUInteger size = 0;
  610 + dispatch_sync(self.ioQueue, ^{
  611 + NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath];
  612 + for (NSString *fileName in fileEnumerator) {
  613 + NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName];
  614 + NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
  615 + size += [attrs fileSize];
  616 + }
  617 + });
  618 + return size;
  619 +}
  620 +
  621 +- (NSUInteger)getDiskCount {
  622 + __block NSUInteger count = 0;
  623 + dispatch_sync(self.ioQueue, ^{
  624 + NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath];
  625 + count = [[fileEnumerator allObjects] count];
  626 + });
  627 + return count;
  628 +}
  629 +
  630 +- (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock {
  631 + NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES];
  632 +
  633 + dispatch_async(self.ioQueue, ^{
  634 + NSUInteger fileCount = 0;
  635 + NSUInteger totalSize = 0;
  636 +
  637 + NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtURL:diskCacheURL
  638 + includingPropertiesForKeys:@[NSFileSize]
  639 + options:NSDirectoryEnumerationSkipsHiddenFiles
  640 + errorHandler:NULL];
  641 +
  642 + for (NSURL *fileURL in fileEnumerator) {
  643 + NSNumber *fileSize;
  644 + [fileURL getResourceValue:&fileSize forKey:NSURLFileSizeKey error:NULL];
  645 + totalSize += [fileSize unsignedIntegerValue];
  646 + fileCount += 1;
  647 + }
  648 +
  649 + if (completionBlock) {
  650 + dispatch_async(dispatch_get_main_queue(), ^{
  651 + completionBlock(fileCount, totalSize);
  652 + });
  653 + }
  654 + });
  655 +}
  656 +
  657 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/SDWebImageCompat.h 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + * (c) Jamie Pinkham
  5 + *
  6 + * For the full copyright and license information, please view the LICENSE
  7 + * file that was distributed with this source code.
  8 + */
  9 +
  10 +#import <TargetConditionals.h>
  11 +
  12 +#ifdef __OBJC_GC__
  13 +#error SDWebImage does not support Objective-C Garbage Collection
  14 +#endif
  15 +
  16 +#if __IPHONE_OS_VERSION_MIN_REQUIRED != 20000 && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0
  17 +#error SDWebImage doesn't support Deployment Target version < 5.0
  18 +#endif
  19 +
  20 +#if !TARGET_OS_IPHONE
  21 +#import <AppKit/AppKit.h>
  22 +#ifndef UIImage
  23 +#define UIImage NSImage
  24 +#endif
  25 +#ifndef UIImageView
  26 +#define UIImageView NSImageView
  27 +#endif
  28 +#else
  29 +
  30 +#import <UIKit/UIKit.h>
  31 +
  32 +#endif
  33 +
  34 +#ifndef NS_ENUM
  35 +#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
  36 +#endif
  37 +
  38 +#ifndef NS_OPTIONS
  39 +#define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
  40 +#endif
  41 +
  42 +#if OS_OBJECT_USE_OBJC
  43 + #undef SDDispatchQueueRelease
  44 + #undef SDDispatchQueueSetterSementics
  45 + #define SDDispatchQueueRelease(q)
  46 + #define SDDispatchQueueSetterSementics strong
  47 +#else
  48 +#undef SDDispatchQueueRelease
  49 +#undef SDDispatchQueueSetterSementics
  50 +#define SDDispatchQueueRelease(q) (dispatch_release(q))
  51 +#define SDDispatchQueueSetterSementics assign
  52 +#endif
  53 +
  54 +extern UIImage *SDScaledImageForKey(NSString *key, UIImage *image);
  55 +
  56 +typedef void(^SDWebImageNoParamsBlock)();
  57 +
  58 +extern NSString *const SDWebImageErrorDomain;
  59 +
  60 +#define dispatch_main_sync_safe(block)\
  61 + if ([NSThread isMainThread]) {\
  62 + block();\
  63 + } else {\
  64 + dispatch_sync(dispatch_get_main_queue(), block);\
  65 + }
  66 +
  67 +#define dispatch_main_async_safe(block)\
  68 + if ([NSThread isMainThread]) {\
  69 + block();\
  70 + } else {\
  71 + dispatch_async(dispatch_get_main_queue(), block);\
  72 + }
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/SDWebImageCompat.m 0 → 100755
  1 +//
  2 +// SDWebImageCompat.m
  3 +// SDWebImage
  4 +//
  5 +// Created by Olivier Poitrey on 11/12/12.
  6 +// Copyright (c) 2012 Dailymotion. All rights reserved.
  7 +//
  8 +
  9 +#import "SDWebImageCompat.h"
  10 +
  11 +#if !__has_feature(objc_arc)
  12 +#error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag
  13 +#endif
  14 +
  15 +inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) {
  16 + if (!image) {
  17 + return nil;
  18 + }
  19 +
  20 + if ([image.images count] > 0) {
  21 + NSMutableArray *scaledImages = [NSMutableArray array];
  22 +
  23 + for (UIImage *tempImage in image.images) {
  24 + [scaledImages addObject:SDScaledImageForKey(key, tempImage)];
  25 + }
  26 +
  27 + return [UIImage animatedImageWithImages:scaledImages duration:image.duration];
  28 + }
  29 + else {
  30 + if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
  31 + CGFloat scale = 1;
  32 + if (key.length >= 8) {
  33 + NSRange range = [key rangeOfString:@"@2x."];
  34 + if (range.location != NSNotFound) {
  35 + scale = 2.0;
  36 + }
  37 +
  38 + range = [key rangeOfString:@"@3x."];
  39 + if (range.location != NSNotFound) {
  40 + scale = 3.0;
  41 + }
  42 + }
  43 +
  44 + UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation];
  45 + image = scaledImage;
  46 + }
  47 + return image;
  48 + }
  49 +}
  50 +
  51 +NSString *const SDWebImageErrorDomain = @"SDWebImageErrorDomain";
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/SDWebImageDecoder.h 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * Created by james <https://github.com/mystcolor> on 9/28/11.
  6 + *
  7 + * For the full copyright and license information, please view the LICENSE
  8 + * file that was distributed with this source code.
  9 + */
  10 +
  11 +#import <Foundation/Foundation.h>
  12 +#import "SDWebImageCompat.h"
  13 +
  14 +@interface UIImage (ForceDecode)
  15 +
  16 ++ (UIImage *)decodedImageWithImage:(UIImage *)image;
  17 +
  18 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/SDWebImageDecoder.m 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * Created by james <https://github.com/mystcolor> on 9/28/11.
  6 + *
  7 + * For the full copyright and license information, please view the LICENSE
  8 + * file that was distributed with this source code.
  9 + */
  10 +
  11 +#import "SDWebImageDecoder.h"
  12 +
  13 +@implementation UIImage (ForceDecode)
  14 +
  15 ++ (UIImage *)decodedImageWithImage:(UIImage *)image {
  16 + // while downloading huge amount of images
  17 + // autorelease the bitmap context
  18 + // and all vars to help system to free memory
  19 + // when there are memory warning.
  20 + // on iOS7, do not forget to call
  21 + // [[SDImageCache sharedImageCache] clearMemory];
  22 +
  23 + if (image == nil) { // Prevent "CGBitmapContextCreateImage: invalid context 0x0" error
  24 + return nil;
  25 + }
  26 +
  27 + @autoreleasepool{
  28 + // do not decode animated images
  29 + if (image.images != nil) {
  30 + return image;
  31 + }
  32 +
  33 + CGImageRef imageRef = image.CGImage;
  34 +
  35 + CGImageAlphaInfo alpha = CGImageGetAlphaInfo(imageRef);
  36 + BOOL anyAlpha = (alpha == kCGImageAlphaFirst ||
  37 + alpha == kCGImageAlphaLast ||
  38 + alpha == kCGImageAlphaPremultipliedFirst ||
  39 + alpha == kCGImageAlphaPremultipliedLast);
  40 + if (anyAlpha) {
  41 + return image;
  42 + }
  43 +
  44 + // current
  45 + CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef));
  46 + CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef);
  47 +
  48 + BOOL unsupportedColorSpace = (imageColorSpaceModel == kCGColorSpaceModelUnknown ||
  49 + imageColorSpaceModel == kCGColorSpaceModelMonochrome ||
  50 + imageColorSpaceModel == kCGColorSpaceModelCMYK ||
  51 + imageColorSpaceModel == kCGColorSpaceModelIndexed);
  52 + if (unsupportedColorSpace) {
  53 + colorspaceRef = CGColorSpaceCreateDeviceRGB();
  54 + }
  55 +
  56 + size_t width = CGImageGetWidth(imageRef);
  57 + size_t height = CGImageGetHeight(imageRef);
  58 + NSUInteger bytesPerPixel = 4;
  59 + NSUInteger bytesPerRow = bytesPerPixel * width;
  60 + NSUInteger bitsPerComponent = 8;
  61 +
  62 +
  63 + // kCGImageAlphaNone is not supported in CGBitmapContextCreate.
  64 + // Since the original image here has no alpha info, use kCGImageAlphaNoneSkipLast
  65 + // to create bitmap graphics contexts without alpha info.
  66 + CGContextRef context = CGBitmapContextCreate(NULL,
  67 + width,
  68 + height,
  69 + bitsPerComponent,
  70 + bytesPerRow,
  71 + colorspaceRef,
  72 + kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast);
  73 +
  74 + // Draw the image into the context and retrieve the new bitmap image without alpha
  75 + CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
  76 + CGImageRef imageRefWithoutAlpha = CGBitmapContextCreateImage(context);
  77 + UIImage *imageWithoutAlpha = [UIImage imageWithCGImage:imageRefWithoutAlpha
  78 + scale:image.scale
  79 + orientation:image.imageOrientation];
  80 +
  81 + if (unsupportedColorSpace) {
  82 + CGColorSpaceRelease(colorspaceRef);
  83 + }
  84 +
  85 + CGContextRelease(context);
  86 + CGImageRelease(imageRefWithoutAlpha);
  87 +
  88 + return imageWithoutAlpha;
  89 + }
  90 +}
  91 +
  92 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/SDWebImageDownloader.h 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "SDWebImageCompat.h"
  11 +#import "SDWebImageOperation.h"
  12 +
  13 +typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) {
  14 + SDWebImageDownloaderLowPriority = 1 << 0,
  15 + SDWebImageDownloaderProgressiveDownload = 1 << 1,
  16 +
  17 + /**
  18 + * By default, request prevent the use of NSURLCache. With this flag, NSURLCache
  19 + * is used with default policies.
  20 + */
  21 + SDWebImageDownloaderUseNSURLCache = 1 << 2,
  22 +
  23 + /**
  24 + * Call completion block with nil image/imageData if the image was read from NSURLCache
  25 + * (to be combined with `SDWebImageDownloaderUseNSURLCache`).
  26 + */
  27 +
  28 + SDWebImageDownloaderIgnoreCachedResponse = 1 << 3,
  29 + /**
  30 + * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for
  31 + * extra time in background to let the request finish. If the background task expires the operation will be cancelled.
  32 + */
  33 +
  34 + SDWebImageDownloaderContinueInBackground = 1 << 4,
  35 +
  36 + /**
  37 + * Handles cookies stored in NSHTTPCookieStore by setting
  38 + * NSMutableURLRequest.HTTPShouldHandleCookies = YES;
  39 + */
  40 + SDWebImageDownloaderHandleCookies = 1 << 5,
  41 +
  42 + /**
  43 + * Enable to allow untrusted SSL certificates.
  44 + * Useful for testing purposes. Use with caution in production.
  45 + */
  46 + SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6,
  47 +
  48 + /**
  49 + * Put the image in the high priority queue.
  50 + */
  51 + SDWebImageDownloaderHighPriority = 1 << 7,
  52 +};
  53 +
  54 +typedef NS_ENUM(NSInteger, SDWebImageDownloaderExecutionOrder) {
  55 + /**
  56 + * Default value. All download operations will execute in queue style (first-in-first-out).
  57 + */
  58 + SDWebImageDownloaderFIFOExecutionOrder,
  59 +
  60 + /**
  61 + * All download operations will execute in stack style (last-in-first-out).
  62 + */
  63 + SDWebImageDownloaderLIFOExecutionOrder
  64 +};
  65 +
  66 +extern NSString *const SDWebImageDownloadStartNotification;
  67 +extern NSString *const SDWebImageDownloadStopNotification;
  68 +
  69 +typedef void(^SDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize);
  70 +
  71 +typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, NSError *error, BOOL finished);
  72 +
  73 +typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDictionary *headers);
  74 +
  75 +/**
  76 + * Asynchronous downloader dedicated and optimized for image loading.
  77 + */
  78 +@interface SDWebImageDownloader : NSObject
  79 +
  80 +/**
  81 + * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory.
  82 + * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption.
  83 + */
  84 +@property (assign, nonatomic) BOOL shouldDecompressImages;
  85 +
  86 +@property (assign, nonatomic) NSInteger maxConcurrentDownloads;
  87 +
  88 +/**
  89 + * Shows the current amount of downloads that still need to be downloaded
  90 + */
  91 +@property (readonly, nonatomic) NSUInteger currentDownloadCount;
  92 +
  93 +
  94 +/**
  95 + * The timeout value (in seconds) for the download operation. Default: 15.0.
  96 + */
  97 +@property (assign, nonatomic) NSTimeInterval downloadTimeout;
  98 +
  99 +
  100 +/**
  101 + * Changes download operations execution order. Default value is `SDWebImageDownloaderFIFOExecutionOrder`.
  102 + */
  103 +@property (assign, nonatomic) SDWebImageDownloaderExecutionOrder executionOrder;
  104 +
  105 +/**
  106 + * Singleton method, returns the shared instance
  107 + *
  108 + * @return global shared instance of downloader class
  109 + */
  110 ++ (SDWebImageDownloader *)sharedDownloader;
  111 +
  112 +/**
  113 + * Set the default URL credential to be set for request operations.
  114 + */
  115 +@property (strong, nonatomic) NSURLCredential *urlCredential;
  116 +
  117 +/**
  118 + * Set username
  119 + */
  120 +@property (strong, nonatomic) NSString *username;
  121 +
  122 +/**
  123 + * Set password
  124 + */
  125 +@property (strong, nonatomic) NSString *password;
  126 +
  127 +/**
  128 + * Set filter to pick headers for downloading image HTTP request.
  129 + *
  130 + * This block will be invoked for each downloading image request, returned
  131 + * NSDictionary will be used as headers in corresponding HTTP request.
  132 + */
  133 +@property (nonatomic, copy) SDWebImageDownloaderHeadersFilterBlock headersFilter;
  134 +
  135 +/**
  136 + * Set a value for a HTTP header to be appended to each download HTTP request.
  137 + *
  138 + * @param value The value for the header field. Use `nil` value to remove the header.
  139 + * @param field The name of the header field to set.
  140 + */
  141 +- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field;
  142 +
  143 +/**
  144 + * Returns the value of the specified HTTP header field.
  145 + *
  146 + * @return The value associated with the header field field, or `nil` if there is no corresponding header field.
  147 + */
  148 +- (NSString *)valueForHTTPHeaderField:(NSString *)field;
  149 +
  150 +/**
  151 + * Sets a subclass of `SDWebImageDownloaderOperation` as the default
  152 + * `NSOperation` to be used each time SDWebImage constructs a request
  153 + * operation to download an image.
  154 + *
  155 + * @param operationClass The subclass of `SDWebImageDownloaderOperation` to set
  156 + * as default. Passing `nil` will revert to `SDWebImageDownloaderOperation`.
  157 + */
  158 +- (void)setOperationClass:(Class)operationClass;
  159 +
  160 +/**
  161 + * Creates a SDWebImageDownloader async downloader instance with a given URL
  162 + *
  163 + * The delegate will be informed when the image is finish downloaded or an error has happen.
  164 + *
  165 + * @see SDWebImageDownloaderDelegate
  166 + *
  167 + * @param url The URL to the image to download
  168 + * @param options The options to be used for this download
  169 + * @param progressBlock A block called repeatedly while the image is downloading
  170 + * @param completedBlock A block called once the download is completed.
  171 + * If the download succeeded, the image parameter is set, in case of error,
  172 + * error parameter is set with the error. The last parameter is always YES
  173 + * if SDWebImageDownloaderProgressiveDownload isn't use. With the
  174 + * SDWebImageDownloaderProgressiveDownload option, this block is called
  175 + * repeatedly with the partial image object and the finished argument set to NO
  176 + * before to be called a last time with the full image and finished argument
  177 + * set to YES. In case of error, the finished argument is always YES.
  178 + *
  179 + * @return A cancellable SDWebImageOperation
  180 + */
  181 +- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
  182 + options:(SDWebImageDownloaderOptions)options
  183 + progress:(SDWebImageDownloaderProgressBlock)progressBlock
  184 + completed:(SDWebImageDownloaderCompletedBlock)completedBlock;
  185 +
  186 +/**
  187 + * Sets the download queue suspension state
  188 + */
  189 +- (void)setSuspended:(BOOL)suspended;
  190 +
  191 +/**
  192 + * Cancels all download operations in the queue
  193 + */
  194 +- (void)cancelAllDownloads;
  195 +
  196 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/SDWebImageDownloader.m 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import "SDWebImageDownloader.h"
  10 +#import "SDWebImageDownloaderOperation.h"
  11 +#import <ImageIO/ImageIO.h>
  12 +
  13 +static NSString *const kProgressCallbackKey = @"progress";
  14 +static NSString *const kCompletedCallbackKey = @"completed";
  15 +
  16 +@interface SDWebImageDownloader () <NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
  17 +
  18 +@property (strong, nonatomic) NSOperationQueue *downloadQueue;
  19 +@property (weak, nonatomic) NSOperation *lastAddedOperation;
  20 +@property (assign, nonatomic) Class operationClass;
  21 +@property (strong, nonatomic) NSMutableDictionary *URLCallbacks;
  22 +@property (strong, nonatomic) NSMutableDictionary *HTTPHeaders;
  23 +// This queue is used to serialize the handling of the network responses of all the download operation in a single queue
  24 +@property (SDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t barrierQueue;
  25 +
  26 +// The session in which data tasks will run
  27 +@property (strong, nonatomic) NSURLSession *session;
  28 +
  29 +@end
  30 +
  31 +@implementation SDWebImageDownloader
  32 +
  33 ++ (void)initialize {
  34 + // Bind SDNetworkActivityIndicator if available (download it here: http://github.com/rs/SDNetworkActivityIndicator )
  35 + // To use it, just add #import "SDNetworkActivityIndicator.h" in addition to the SDWebImage import
  36 + if (NSClassFromString(@"SDNetworkActivityIndicator")) {
  37 +
  38 +#pragma clang diagnostic push
  39 +#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
  40 + id activityIndicator = [NSClassFromString(@"SDNetworkActivityIndicator") performSelector:NSSelectorFromString(@"sharedActivityIndicator")];
  41 +#pragma clang diagnostic pop
  42 +
  43 + // Remove observer in case it was previously added.
  44 + [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:SDWebImageDownloadStartNotification object:nil];
  45 + [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:SDWebImageDownloadStopNotification object:nil];
  46 +
  47 + [[NSNotificationCenter defaultCenter] addObserver:activityIndicator
  48 + selector:NSSelectorFromString(@"startActivity")
  49 + name:SDWebImageDownloadStartNotification object:nil];
  50 + [[NSNotificationCenter defaultCenter] addObserver:activityIndicator
  51 + selector:NSSelectorFromString(@"stopActivity")
  52 + name:SDWebImageDownloadStopNotification object:nil];
  53 + }
  54 +}
  55 +
  56 ++ (SDWebImageDownloader *)sharedDownloader {
  57 + static dispatch_once_t once;
  58 + static id instance;
  59 + dispatch_once(&once, ^{
  60 + instance = [self new];
  61 + });
  62 + return instance;
  63 +}
  64 +
  65 +- (id)init {
  66 + if ((self = [super init])) {
  67 + _operationClass = [SDWebImageDownloaderOperation class];
  68 + _shouldDecompressImages = YES;
  69 + _executionOrder = SDWebImageDownloaderFIFOExecutionOrder;
  70 + _downloadQueue = [NSOperationQueue new];
  71 + _downloadQueue.maxConcurrentOperationCount = 6;
  72 + _URLCallbacks = [NSMutableDictionary new];
  73 +#ifdef SD_WEBP
  74 + _HTTPHeaders = [@{@"Accept": @"image/webp,image/*;q=0.8"} mutableCopy];
  75 +#else
  76 + _HTTPHeaders = [@{@"Accept": @"image/*;q=0.8"} mutableCopy];
  77 +#endif
  78 + _barrierQueue = dispatch_queue_create("com.hackemist.SDWebImageDownloaderBarrierQueue", DISPATCH_QUEUE_CONCURRENT);
  79 + _downloadTimeout = 15.0;
  80 +
  81 + NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
  82 + sessionConfig.timeoutIntervalForRequest = _downloadTimeout;
  83 +
  84 + /**
  85 + * Create the session for this task
  86 + * We send nil as delegate queue so that the session creates a serial operation queue for performing all delegate
  87 + * method calls and completion handler calls.
  88 + */
  89 + self.session = [NSURLSession sessionWithConfiguration:sessionConfig
  90 + delegate:self
  91 + delegateQueue:nil];
  92 + }
  93 + return self;
  94 +}
  95 +
  96 +- (void)dealloc {
  97 + [self.session invalidateAndCancel];
  98 + self.session = nil;
  99 +
  100 + [self.downloadQueue cancelAllOperations];
  101 + SDDispatchQueueRelease(_barrierQueue);
  102 +}
  103 +
  104 +- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field {
  105 + if (value) {
  106 + self.HTTPHeaders[field] = value;
  107 + }
  108 + else {
  109 + [self.HTTPHeaders removeObjectForKey:field];
  110 + }
  111 +}
  112 +
  113 +- (NSString *)valueForHTTPHeaderField:(NSString *)field {
  114 + return self.HTTPHeaders[field];
  115 +}
  116 +
  117 +- (void)setMaxConcurrentDownloads:(NSInteger)maxConcurrentDownloads {
  118 + _downloadQueue.maxConcurrentOperationCount = maxConcurrentDownloads;
  119 +}
  120 +
  121 +- (NSUInteger)currentDownloadCount {
  122 + return _downloadQueue.operationCount;
  123 +}
  124 +
  125 +- (NSInteger)maxConcurrentDownloads {
  126 + return _downloadQueue.maxConcurrentOperationCount;
  127 +}
  128 +
  129 +- (void)setOperationClass:(Class)operationClass {
  130 + _operationClass = operationClass ?: [SDWebImageDownloaderOperation class];
  131 +}
  132 +
  133 +- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock {
  134 + __block SDWebImageDownloaderOperation *operation;
  135 + __weak __typeof(self)wself = self;
  136 +
  137 + [self addProgressCallback:progressBlock completedBlock:completedBlock forURL:url createCallback:^{
  138 + NSTimeInterval timeoutInterval = wself.downloadTimeout;
  139 + if (timeoutInterval == 0.0) {
  140 + timeoutInterval = 15.0;
  141 + }
  142 +
  143 + // In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise
  144 + NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:timeoutInterval];
  145 + request.HTTPShouldHandleCookies = (options & SDWebImageDownloaderHandleCookies);
  146 + request.HTTPShouldUsePipelining = YES;
  147 + if (wself.headersFilter) {
  148 + request.allHTTPHeaderFields = wself.headersFilter(url, [wself.HTTPHeaders copy]);
  149 + }
  150 + else {
  151 + request.allHTTPHeaderFields = wself.HTTPHeaders;
  152 + }
  153 + operation = [[wself.operationClass alloc] initWithRequest:request
  154 + inSession:self.session
  155 + options:options
  156 + progress:^(NSInteger receivedSize, NSInteger expectedSize) {
  157 + SDWebImageDownloader *sself = wself;
  158 + if (!sself) return;
  159 + __block NSArray *callbacksForURL;
  160 + dispatch_sync(sself.barrierQueue, ^{
  161 + callbacksForURL = [sself.URLCallbacks[url] copy];
  162 + });
  163 + for (NSDictionary *callbacks in callbacksForURL) {
  164 + dispatch_async(dispatch_get_main_queue(), ^{
  165 + SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey];
  166 + if (callback) callback(receivedSize, expectedSize);
  167 + });
  168 + }
  169 + }
  170 + completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
  171 + SDWebImageDownloader *sself = wself;
  172 + if (!sself) return;
  173 + __block NSArray *callbacksForURL;
  174 + dispatch_barrier_sync(sself.barrierQueue, ^{
  175 + callbacksForURL = [sself.URLCallbacks[url] copy];
  176 + if (finished) {
  177 + [sself.URLCallbacks removeObjectForKey:url];
  178 + }
  179 + });
  180 + for (NSDictionary *callbacks in callbacksForURL) {
  181 + SDWebImageDownloaderCompletedBlock callback = callbacks[kCompletedCallbackKey];
  182 + if (callback) callback(image, data, error, finished);
  183 + }
  184 + }
  185 + cancelled:^{
  186 + SDWebImageDownloader *sself = wself;
  187 + if (!sself) return;
  188 + dispatch_barrier_async(sself.barrierQueue, ^{
  189 + [sself.URLCallbacks removeObjectForKey:url];
  190 + });
  191 + }];
  192 + operation.shouldDecompressImages = wself.shouldDecompressImages;
  193 +
  194 + if (wself.urlCredential) {
  195 + operation.credential = wself.urlCredential;
  196 + } else if (wself.username && wself.password) {
  197 + operation.credential = [NSURLCredential credentialWithUser:wself.username password:wself.password persistence:NSURLCredentialPersistenceForSession];
  198 + }
  199 +
  200 + if (options & SDWebImageDownloaderHighPriority) {
  201 + operation.queuePriority = NSOperationQueuePriorityHigh;
  202 + } else if (options & SDWebImageDownloaderLowPriority) {
  203 + operation.queuePriority = NSOperationQueuePriorityLow;
  204 + }
  205 +
  206 + [wself.downloadQueue addOperation:operation];
  207 + if (wself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) {
  208 + // Emulate LIFO execution order by systematically adding new operations as last operation's dependency
  209 + [wself.lastAddedOperation addDependency:operation];
  210 + wself.lastAddedOperation = operation;
  211 + }
  212 + }];
  213 +
  214 + return operation;
  215 +}
  216 +
  217 +- (void)addProgressCallback:(SDWebImageDownloaderProgressBlock)progressBlock completedBlock:(SDWebImageDownloaderCompletedBlock)completedBlock forURL:(NSURL *)url createCallback:(SDWebImageNoParamsBlock)createCallback {
  218 + // The URL will be used as the key to the callbacks dictionary so it cannot be nil. If it is nil immediately call the completed block with no image or data.
  219 + if (url == nil) {
  220 + if (completedBlock != nil) {
  221 + completedBlock(nil, nil, nil, NO);
  222 + }
  223 + return;
  224 + }
  225 +
  226 + dispatch_barrier_sync(self.barrierQueue, ^{
  227 + BOOL first = NO;
  228 + if (!self.URLCallbacks[url]) {
  229 + self.URLCallbacks[url] = [NSMutableArray new];
  230 + first = YES;
  231 + }
  232 +
  233 + // Handle single download of simultaneous download request for the same URL
  234 + NSMutableArray *callbacksForURL = self.URLCallbacks[url];
  235 + NSMutableDictionary *callbacks = [NSMutableDictionary new];
  236 + if (progressBlock) callbacks[kProgressCallbackKey] = [progressBlock copy];
  237 + if (completedBlock) callbacks[kCompletedCallbackKey] = [completedBlock copy];
  238 + [callbacksForURL addObject:callbacks];
  239 + self.URLCallbacks[url] = callbacksForURL;
  240 +
  241 + if (first) {
  242 + createCallback();
  243 + }
  244 + });
  245 +}
  246 +
  247 +- (void)setSuspended:(BOOL)suspended {
  248 + [self.downloadQueue setSuspended:suspended];
  249 +}
  250 +
  251 +- (void)cancelAllDownloads {
  252 + [self.downloadQueue cancelAllOperations];
  253 +}
  254 +
  255 +#pragma mark Helper methods
  256 +
  257 +- (SDWebImageDownloaderOperation *)operationWithTask:(NSURLSessionTask *)task {
  258 + SDWebImageDownloaderOperation *returnOperation = nil;
  259 + for (SDWebImageDownloaderOperation *operation in self.downloadQueue.operations) {
  260 + if (operation.dataTask.taskIdentifier == task.taskIdentifier) {
  261 + returnOperation = operation;
  262 + break;
  263 + }
  264 + }
  265 + return returnOperation;
  266 +}
  267 +
  268 +#pragma mark NSURLSessionDataDelegate
  269 +
  270 +- (void)URLSession:(NSURLSession *)session
  271 + dataTask:(NSURLSessionDataTask *)dataTask
  272 +didReceiveResponse:(NSURLResponse *)response
  273 + completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
  274 +
  275 + // Identify the operation that runs this task and pass it the delegate method
  276 + SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask];
  277 +
  278 + [dataOperation URLSession:session dataTask:dataTask didReceiveResponse:response completionHandler:completionHandler];
  279 +}
  280 +
  281 +- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
  282 +
  283 + // Identify the operation that runs this task and pass it the delegate method
  284 + SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask];
  285 +
  286 + [dataOperation URLSession:session dataTask:dataTask didReceiveData:data];
  287 +}
  288 +
  289 +- (void)URLSession:(NSURLSession *)session
  290 + dataTask:(NSURLSessionDataTask *)dataTask
  291 + willCacheResponse:(NSCachedURLResponse *)proposedResponse
  292 + completionHandler:(void (^)(NSCachedURLResponse *cachedResponse))completionHandler {
  293 +
  294 + // Identify the operation that runs this task and pass it the delegate method
  295 + SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:dataTask];
  296 +
  297 + [dataOperation URLSession:session dataTask:dataTask willCacheResponse:proposedResponse completionHandler:completionHandler];
  298 +}
  299 +
  300 +#pragma mark NSURLSessionTaskDelegate
  301 +
  302 +- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
  303 + // Identify the operation that runs this task and pass it the delegate method
  304 + SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task];
  305 +
  306 + [dataOperation URLSession:session task:task didCompleteWithError:error];
  307 +}
  308 +
  309 +- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
  310 +
  311 + // Identify the operation that runs this task and pass it the delegate method
  312 + SDWebImageDownloaderOperation *dataOperation = [self operationWithTask:task];
  313 +
  314 + [dataOperation URLSession:session task:task didReceiveChallenge:challenge completionHandler:completionHandler];
  315 +}
  316 +
  317 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/SDWebImageDownloaderOperation.h 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "SDWebImageDownloader.h"
  11 +#import "SDWebImageOperation.h"
  12 +
  13 +extern NSString *const SDWebImageDownloadStartNotification;
  14 +extern NSString *const SDWebImageDownloadReceiveResponseNotification;
  15 +extern NSString *const SDWebImageDownloadStopNotification;
  16 +extern NSString *const SDWebImageDownloadFinishNotification;
  17 +
  18 +@interface SDWebImageDownloaderOperation : NSOperation <SDWebImageOperation, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
  19 +
  20 +/**
  21 + * The request used by the operation's task.
  22 + */
  23 +@property (strong, nonatomic, readonly) NSURLRequest *request;
  24 +
  25 +/**
  26 + * The operation's task
  27 + */
  28 +@property (strong, nonatomic, readonly) NSURLSessionTask *dataTask;
  29 +
  30 +
  31 +@property (assign, nonatomic) BOOL shouldDecompressImages;
  32 +
  33 +/**
  34 + * Was used to determine whether the URL connection should consult the credential storage for authenticating the connection.
  35 + * @deprecated Not used for a couple of versions
  36 + */
  37 +@property (nonatomic, assign) BOOL shouldUseCredentialStorage __deprecated_msg("Property deprecated. Does nothing. Kept only for backwards compatibility");
  38 +
  39 +/**
  40 + * The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`.
  41 + *
  42 + * This will be overridden by any shared credentials that exist for the username or password of the request URL, if present.
  43 + */
  44 +@property (nonatomic, strong) NSURLCredential *credential;
  45 +
  46 +/**
  47 + * The SDWebImageDownloaderOptions for the receiver.
  48 + */
  49 +@property (assign, nonatomic, readonly) SDWebImageDownloaderOptions options;
  50 +
  51 +/**
  52 + * The expected size of data.
  53 + */
  54 +@property (assign, nonatomic) NSInteger expectedSize;
  55 +
  56 +/**
  57 + * The response returned by the operation's connection.
  58 + */
  59 +@property (strong, nonatomic) NSURLResponse *response;
  60 +
  61 +/**
  62 + * Initializes a `SDWebImageDownloaderOperation` object
  63 + *
  64 + * @see SDWebImageDownloaderOperation
  65 + *
  66 + * @param request the URL request
  67 + * @param session the URL session in which this operation will run
  68 + * @param options downloader options
  69 + * @param progressBlock the block executed when a new chunk of data arrives.
  70 + * @note the progress block is executed on a background queue
  71 + * @param completedBlock the block executed when the download is done.
  72 + * @note the completed block is executed on the main queue for success. If errors are found, there is a chance the block will be executed on a background queue
  73 + * @param cancelBlock the block executed if the download (operation) is cancelled
  74 + *
  75 + * @return the initialized instance
  76 + */
  77 +- (id)initWithRequest:(NSURLRequest *)request
  78 + inSession:(NSURLSession *)session
  79 + options:(SDWebImageDownloaderOptions)options
  80 + progress:(SDWebImageDownloaderProgressBlock)progressBlock
  81 + completed:(SDWebImageDownloaderCompletedBlock)completedBlock
  82 + cancelled:(SDWebImageNoParamsBlock)cancelBlock;
  83 +
  84 +/**
  85 + * Initializes a `SDWebImageDownloaderOperation` object
  86 + *
  87 + * @see SDWebImageDownloaderOperation
  88 + *
  89 + * @param request the URL request
  90 + * @param options downloader options
  91 + * @param progressBlock the block executed when a new chunk of data arrives.
  92 + * @note the progress block is executed on a background queue
  93 + * @param completedBlock the block executed when the download is done.
  94 + * @note the completed block is executed on the main queue for success. If errors are found, there is a chance the block will be executed on a background queue
  95 + * @param cancelBlock the block executed if the download (operation) is cancelled
  96 + *
  97 + * @return the initialized instance. The operation will run in a separate session created for this operation
  98 + */
  99 +- (id)initWithRequest:(NSURLRequest *)request
  100 + options:(SDWebImageDownloaderOptions)options
  101 + progress:(SDWebImageDownloaderProgressBlock)progressBlock
  102 + completed:(SDWebImageDownloaderCompletedBlock)completedBlock
  103 + cancelled:(SDWebImageNoParamsBlock)cancelBlock
  104 +__deprecated_msg("Method deprecated. Use `initWithRequest:inSession:options:progress:completed:cancelled`");
  105 +
  106 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/SDWebImageDownloaderOperation.m 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import "SDWebImageDownloaderOperation.h"
  10 +#import "SDWebImageDecoder.h"
  11 +#import "UIImage+MultiFormat.h"
  12 +#import <ImageIO/ImageIO.h>
  13 +#import "SDWebImageManager.h"
  14 +
  15 +NSString *const SDWebImageDownloadStartNotification = @"SDWebImageDownloadStartNotification";
  16 +NSString *const SDWebImageDownloadReceiveResponseNotification = @"SDWebImageDownloadReceiveResponseNotification";
  17 +NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNotification";
  18 +NSString *const SDWebImageDownloadFinishNotification = @"SDWebImageDownloadFinishNotification";
  19 +
  20 +@interface SDWebImageDownloaderOperation ()
  21 +
  22 +@property (copy, nonatomic) SDWebImageDownloaderProgressBlock progressBlock;
  23 +@property (copy, nonatomic) SDWebImageDownloaderCompletedBlock completedBlock;
  24 +@property (copy, nonatomic) SDWebImageNoParamsBlock cancelBlock;
  25 +
  26 +@property (assign, nonatomic, getter = isExecuting) BOOL executing;
  27 +@property (assign, nonatomic, getter = isFinished) BOOL finished;
  28 +@property (strong, nonatomic) NSMutableData *imageData;
  29 +
  30 +// This is weak because it is injected by whoever manages this session. If this gets nil-ed out, we won't be able to run
  31 +// the task associated with this operation
  32 +@property (weak, nonatomic) NSURLSession *unownedSession;
  33 +// This is set if we're using not using an injected NSURLSession. We're responsible of invalidating this one
  34 +@property (strong, nonatomic) NSURLSession *ownedSession;
  35 +
  36 +@property (strong, nonatomic, readwrite) NSURLSessionTask *dataTask;
  37 +
  38 +@property (strong, atomic) NSThread *thread;
  39 +
  40 +#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
  41 +@property (assign, nonatomic) UIBackgroundTaskIdentifier backgroundTaskId;
  42 +#endif
  43 +
  44 +@end
  45 +
  46 +@implementation SDWebImageDownloaderOperation {
  47 + size_t width, height;
  48 + UIImageOrientation orientation;
  49 + BOOL responseFromCached;
  50 +}
  51 +
  52 +@synthesize executing = _executing;
  53 +@synthesize finished = _finished;
  54 +
  55 +- (id)initWithRequest:(NSURLRequest *)request
  56 + options:(SDWebImageDownloaderOptions)options
  57 + progress:(SDWebImageDownloaderProgressBlock)progressBlock
  58 + completed:(SDWebImageDownloaderCompletedBlock)completedBlock
  59 + cancelled:(SDWebImageNoParamsBlock)cancelBlock {
  60 +
  61 + return [self initWithRequest:request
  62 + inSession:nil
  63 + options:options
  64 + progress:progressBlock
  65 + completed:completedBlock
  66 + cancelled:cancelBlock];
  67 +}
  68 +
  69 +- (id)initWithRequest:(NSURLRequest *)request
  70 + inSession:(NSURLSession *)session
  71 + options:(SDWebImageDownloaderOptions)options
  72 + progress:(SDWebImageDownloaderProgressBlock)progressBlock
  73 + completed:(SDWebImageDownloaderCompletedBlock)completedBlock
  74 + cancelled:(SDWebImageNoParamsBlock)cancelBlock {
  75 + if ((self = [super init])) {
  76 + _request = request;
  77 + _shouldDecompressImages = YES;
  78 + _options = options;
  79 + _progressBlock = [progressBlock copy];
  80 + _completedBlock = [completedBlock copy];
  81 + _cancelBlock = [cancelBlock copy];
  82 + _executing = NO;
  83 + _finished = NO;
  84 + _expectedSize = 0;
  85 + _unownedSession = session;
  86 + responseFromCached = YES; // Initially wrong until `- URLSession:dataTask:willCacheResponse:completionHandler: is called or not called
  87 + }
  88 + return self;
  89 +}
  90 +
  91 +- (void)start {
  92 + @synchronized (self) {
  93 + if (self.isCancelled) {
  94 + self.finished = YES;
  95 + [self reset];
  96 + return;
  97 + }
  98 +
  99 +#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
  100 + Class UIApplicationClass = NSClassFromString(@"UIApplication");
  101 + BOOL hasApplication = UIApplicationClass && [UIApplicationClass respondsToSelector:@selector(sharedApplication)];
  102 + if (hasApplication && [self shouldContinueWhenAppEntersBackground]) {
  103 + __weak __typeof__ (self) wself = self;
  104 + UIApplication * app = [UIApplicationClass performSelector:@selector(sharedApplication)];
  105 + self.backgroundTaskId = [app beginBackgroundTaskWithExpirationHandler:^{
  106 + __strong __typeof (wself) sself = wself;
  107 +
  108 + if (sself) {
  109 + [sself cancel];
  110 +
  111 + [app endBackgroundTask:sself.backgroundTaskId];
  112 + sself.backgroundTaskId = UIBackgroundTaskInvalid;
  113 + }
  114 + }];
  115 + }
  116 +#endif
  117 + NSURLSession *session = self.unownedSession;
  118 + if (!self.unownedSession) {
  119 + NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
  120 + sessionConfig.timeoutIntervalForRequest = 15;
  121 +
  122 + /**
  123 + * Create the session for this task
  124 + * We send nil as delegate queue so that the session creates a serial operation queue for performing all delegate
  125 + * method calls and completion handler calls.
  126 + */
  127 + self.ownedSession = [NSURLSession sessionWithConfiguration:sessionConfig
  128 + delegate:self
  129 + delegateQueue:nil];
  130 + session = self.ownedSession;
  131 + }
  132 +
  133 + self.dataTask = [session dataTaskWithRequest:self.request];
  134 + self.executing = YES;
  135 + self.thread = [NSThread currentThread];
  136 + }
  137 +
  138 + [self.dataTask resume];
  139 +
  140 + if (self.dataTask) {
  141 + if (self.progressBlock) {
  142 + self.progressBlock(0, NSURLResponseUnknownLength);
  143 + }
  144 + dispatch_async(dispatch_get_main_queue(), ^{
  145 + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStartNotification object:self];
  146 + });
  147 + }
  148 + else {
  149 + if (self.completedBlock) {
  150 + self.completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Connection can't be initialized"}], YES);
  151 + }
  152 + }
  153 +
  154 +#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
  155 + Class UIApplicationClass = NSClassFromString(@"UIApplication");
  156 + if(!UIApplicationClass || ![UIApplicationClass respondsToSelector:@selector(sharedApplication)]) {
  157 + return;
  158 + }
  159 + if (self.backgroundTaskId != UIBackgroundTaskInvalid) {
  160 + UIApplication * app = [UIApplication performSelector:@selector(sharedApplication)];
  161 + [app endBackgroundTask:self.backgroundTaskId];
  162 + self.backgroundTaskId = UIBackgroundTaskInvalid;
  163 + }
  164 +#endif
  165 +}
  166 +
  167 +- (void)cancel {
  168 + @synchronized (self) {
  169 + if (self.thread) {
  170 + [self performSelector:@selector(cancelInternalAndStop) onThread:self.thread withObject:nil waitUntilDone:NO];
  171 + }
  172 + else {
  173 + [self cancelInternal];
  174 + }
  175 + }
  176 +}
  177 +
  178 +- (void)cancelInternalAndStop {
  179 + if (self.isFinished) return;
  180 + [self cancelInternal];
  181 +}
  182 +
  183 +- (void)cancelInternal {
  184 + if (self.isFinished) return;
  185 + [super cancel];
  186 + if (self.cancelBlock) self.cancelBlock();
  187 +
  188 + if (self.dataTask) {
  189 + [self.dataTask cancel];
  190 + dispatch_async(dispatch_get_main_queue(), ^{
  191 + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
  192 + });
  193 +
  194 + // As we cancelled the connection, its callback won't be called and thus won't
  195 + // maintain the isFinished and isExecuting flags.
  196 + if (self.isExecuting) self.executing = NO;
  197 + if (!self.isFinished) self.finished = YES;
  198 + }
  199 +
  200 + [self reset];
  201 +}
  202 +
  203 +- (void)done {
  204 + self.finished = YES;
  205 + self.executing = NO;
  206 + [self reset];
  207 +}
  208 +
  209 +- (void)reset {
  210 + self.cancelBlock = nil;
  211 + self.completedBlock = nil;
  212 + self.progressBlock = nil;
  213 + self.dataTask = nil;
  214 + self.imageData = nil;
  215 + self.thread = nil;
  216 + if (self.ownedSession) {
  217 + [self.ownedSession invalidateAndCancel];
  218 + self.ownedSession = nil;
  219 + }
  220 +}
  221 +
  222 +- (void)setFinished:(BOOL)finished {
  223 + [self willChangeValueForKey:@"isFinished"];
  224 + _finished = finished;
  225 + [self didChangeValueForKey:@"isFinished"];
  226 +}
  227 +
  228 +- (void)setExecuting:(BOOL)executing {
  229 + [self willChangeValueForKey:@"isExecuting"];
  230 + _executing = executing;
  231 + [self didChangeValueForKey:@"isExecuting"];
  232 +}
  233 +
  234 +- (BOOL)isConcurrent {
  235 + return YES;
  236 +}
  237 +
  238 +#pragma mark NSURLSessionDataDelegate
  239 +
  240 +- (void)URLSession:(NSURLSession *)session
  241 + dataTask:(NSURLSessionDataTask *)dataTask
  242 +didReceiveResponse:(NSURLResponse *)response
  243 + completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
  244 +
  245 + //'304 Not Modified' is an exceptional one
  246 + if (![response respondsToSelector:@selector(statusCode)] || ([((NSHTTPURLResponse *)response) statusCode] < 400 && [((NSHTTPURLResponse *)response) statusCode] != 304)) {
  247 + NSInteger expected = response.expectedContentLength > 0 ? (NSInteger)response.expectedContentLength : 0;
  248 + self.expectedSize = expected;
  249 + if (self.progressBlock) {
  250 + self.progressBlock(0, expected);
  251 + }
  252 +
  253 + self.imageData = [[NSMutableData alloc] initWithCapacity:expected];
  254 + self.response = response;
  255 + dispatch_async(dispatch_get_main_queue(), ^{
  256 + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadReceiveResponseNotification object:self];
  257 + });
  258 + }
  259 + else {
  260 + NSUInteger code = [((NSHTTPURLResponse *)response) statusCode];
  261 +
  262 + //This is the case when server returns '304 Not Modified'. It means that remote image is not changed.
  263 + //In case of 304 we need just cancel the operation and return cached image from the cache.
  264 + if (code == 304) {
  265 + [self cancelInternal];
  266 + } else {
  267 + [self.dataTask cancel];
  268 + }
  269 + dispatch_async(dispatch_get_main_queue(), ^{
  270 + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
  271 + });
  272 +
  273 + if (self.completedBlock) {
  274 + self.completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:[((NSHTTPURLResponse *)response) statusCode] userInfo:nil], YES);
  275 + }
  276 + [self done];
  277 + }
  278 +
  279 + if (completionHandler) {
  280 + completionHandler(NSURLSessionResponseAllow);
  281 + }
  282 +}
  283 +
  284 +- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
  285 + [self.imageData appendData:data];
  286 +
  287 + if ((self.options & SDWebImageDownloaderProgressiveDownload) && self.expectedSize > 0 && self.completedBlock) {
  288 + // The following code is from http://www.cocoaintheshell.com/2011/05/progressive-images-download-imageio/
  289 + // Thanks to the author @Nyx0uf
  290 +
  291 + // Get the total bytes downloaded
  292 + const NSInteger totalSize = self.imageData.length;
  293 +
  294 + // Update the data source, we must pass ALL the data, not just the new bytes
  295 + CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)self.imageData, NULL);
  296 +
  297 + if (width + height == 0) {
  298 + CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
  299 + if (properties) {
  300 + NSInteger orientationValue = -1;
  301 + CFTypeRef val = CFDictionaryGetValue(properties, kCGImagePropertyPixelHeight);
  302 + if (val) CFNumberGetValue(val, kCFNumberLongType, &height);
  303 + val = CFDictionaryGetValue(properties, kCGImagePropertyPixelWidth);
  304 + if (val) CFNumberGetValue(val, kCFNumberLongType, &width);
  305 + val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation);
  306 + if (val) CFNumberGetValue(val, kCFNumberNSIntegerType, &orientationValue);
  307 + CFRelease(properties);
  308 +
  309 + // When we draw to Core Graphics, we lose orientation information,
  310 + // which means the image below born of initWithCGIImage will be
  311 + // oriented incorrectly sometimes. (Unlike the image born of initWithData
  312 + // in didCompleteWithError.) So save it here and pass it on later.
  313 + orientation = [[self class] orientationFromPropertyValue:(orientationValue == -1 ? 1 : orientationValue)];
  314 + }
  315 +
  316 + }
  317 +
  318 + if (width + height > 0 && totalSize < self.expectedSize) {
  319 + // Create the image
  320 + CGImageRef partialImageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
  321 +
  322 +#ifdef TARGET_OS_IPHONE
  323 + // Workaround for iOS anamorphic image
  324 + if (partialImageRef) {
  325 + const size_t partialHeight = CGImageGetHeight(partialImageRef);
  326 + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  327 + CGContextRef bmContext = CGBitmapContextCreate(NULL, width, height, 8, width * 4, colorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);
  328 + CGColorSpaceRelease(colorSpace);
  329 + if (bmContext) {
  330 + CGContextDrawImage(bmContext, (CGRect){.origin.x = 0.0f, .origin.y = 0.0f, .size.width = width, .size.height = partialHeight}, partialImageRef);
  331 + CGImageRelease(partialImageRef);
  332 + partialImageRef = CGBitmapContextCreateImage(bmContext);
  333 + CGContextRelease(bmContext);
  334 + }
  335 + else {
  336 + CGImageRelease(partialImageRef);
  337 + partialImageRef = nil;
  338 + }
  339 + }
  340 +#endif
  341 +
  342 + if (partialImageRef) {
  343 + UIImage *image = [UIImage imageWithCGImage:partialImageRef scale:1 orientation:orientation];
  344 + NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL];
  345 + UIImage *scaledImage = [self scaledImageForKey:key image:image];
  346 + if (self.shouldDecompressImages) {
  347 + image = [UIImage decodedImageWithImage:scaledImage];
  348 + }
  349 + else {
  350 + image = scaledImage;
  351 + }
  352 + CGImageRelease(partialImageRef);
  353 + dispatch_main_sync_safe(^{
  354 + if (self.completedBlock) {
  355 + self.completedBlock(image, nil, nil, NO);
  356 + }
  357 + });
  358 + }
  359 + }
  360 +
  361 + CFRelease(imageSource);
  362 + }
  363 +
  364 + if (self.progressBlock) {
  365 + self.progressBlock(self.imageData.length, self.expectedSize);
  366 + }
  367 +}
  368 +
  369 +- (void)URLSession:(NSURLSession *)session
  370 + dataTask:(NSURLSessionDataTask *)dataTask
  371 + willCacheResponse:(NSCachedURLResponse *)proposedResponse
  372 + completionHandler:(void (^)(NSCachedURLResponse *cachedResponse))completionHandler {
  373 +
  374 + responseFromCached = NO; // If this method is called, it means the response wasn't read from cache
  375 + NSCachedURLResponse *cachedResponse = proposedResponse;
  376 +
  377 + if (self.request.cachePolicy == NSURLRequestReloadIgnoringLocalCacheData) {
  378 + // Prevents caching of responses
  379 + cachedResponse = nil;
  380 + }
  381 + if (completionHandler) {
  382 + completionHandler(cachedResponse);
  383 + }
  384 +}
  385 +
  386 +#pragma mark NSURLSessionTaskDelegate
  387 +
  388 +- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
  389 + @synchronized(self) {
  390 + self.thread = nil;
  391 + self.dataTask = nil;
  392 + dispatch_async(dispatch_get_main_queue(), ^{
  393 + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
  394 + if (!error) {
  395 + [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadFinishNotification object:self];
  396 + }
  397 + });
  398 + }
  399 +
  400 + if (error) {
  401 + if (self.completedBlock) {
  402 + self.completedBlock(nil, nil, error, YES);
  403 + }
  404 + } else {
  405 + SDWebImageDownloaderCompletedBlock completionBlock = self.completedBlock;
  406 +
  407 + if (![[NSURLCache sharedURLCache] cachedResponseForRequest:_request]) {
  408 + responseFromCached = NO;
  409 + }
  410 +
  411 + if (completionBlock) {
  412 + if (self.options & SDWebImageDownloaderIgnoreCachedResponse && responseFromCached) {
  413 + completionBlock(nil, nil, nil, YES);
  414 + } else if (self.imageData) {
  415 + UIImage *image = [UIImage sd_imageWithData:self.imageData];
  416 + NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL];
  417 + image = [self scaledImageForKey:key image:image];
  418 +
  419 + // Do not force decoding animated GIFs
  420 + if (!image.images) {
  421 + if (self.shouldDecompressImages) {
  422 + image = [UIImage decodedImageWithImage:image];
  423 + }
  424 + }
  425 + if (CGSizeEqualToSize(image.size, CGSizeZero)) {
  426 + completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Downloaded image has 0 pixels"}], YES);
  427 + }
  428 + else {
  429 + completionBlock(image, self.imageData, nil, YES);
  430 + }
  431 + } else {
  432 + completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Image data is nil"}], YES);
  433 + }
  434 + }
  435 + }
  436 +
  437 + self.completionBlock = nil;
  438 + [self done];
  439 +}
  440 +
  441 +- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
  442 +
  443 + NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling;
  444 + __block NSURLCredential *credential = nil;
  445 +
  446 + if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
  447 + if (!(self.options & SDWebImageDownloaderAllowInvalidSSLCertificates)) {
  448 + disposition = NSURLSessionAuthChallengePerformDefaultHandling;
  449 + } else {
  450 + credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
  451 + disposition = NSURLSessionAuthChallengeUseCredential;
  452 + }
  453 + } else {
  454 + if ([challenge previousFailureCount] == 0) {
  455 + if (self.credential) {
  456 + credential = self.credential;
  457 + disposition = NSURLSessionAuthChallengeUseCredential;
  458 + } else {
  459 + disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge;
  460 + }
  461 + } else {
  462 + disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge;
  463 + }
  464 + }
  465 +
  466 + if (completionHandler) {
  467 + completionHandler(disposition, credential);
  468 + }
  469 +}
  470 +
  471 +#pragma mark Helper methods
  472 +
  473 ++ (UIImageOrientation)orientationFromPropertyValue:(NSInteger)value {
  474 + switch (value) {
  475 + case 1:
  476 + return UIImageOrientationUp;
  477 + case 3:
  478 + return UIImageOrientationDown;
  479 + case 8:
  480 + return UIImageOrientationLeft;
  481 + case 6:
  482 + return UIImageOrientationRight;
  483 + case 2:
  484 + return UIImageOrientationUpMirrored;
  485 + case 4:
  486 + return UIImageOrientationDownMirrored;
  487 + case 5:
  488 + return UIImageOrientationLeftMirrored;
  489 + case 7:
  490 + return UIImageOrientationRightMirrored;
  491 + default:
  492 + return UIImageOrientationUp;
  493 + }
  494 +}
  495 +
  496 +- (UIImage *)scaledImageForKey:(NSString *)key image:(UIImage *)image {
  497 + return SDScaledImageForKey(key, image);
  498 +}
  499 +
  500 +- (BOOL)shouldContinueWhenAppEntersBackground {
  501 + return self.options & SDWebImageDownloaderContinueInBackground;
  502 +}
  503 +
  504 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/SDWebImageManager.h 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import "SDWebImageCompat.h"
  10 +#import "SDWebImageOperation.h"
  11 +#import "SDWebImageDownloader.h"
  12 +#import "SDImageCache.h"
  13 +
  14 +typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
  15 + /**
  16 + * By default, when a URL fail to be downloaded, the URL is blacklisted so the library won't keep trying.
  17 + * This flag disable this blacklisting.
  18 + */
  19 + SDWebImageRetryFailed = 1 << 0,
  20 +
  21 + /**
  22 + * By default, image downloads are started during UI interactions, this flags disable this feature,
  23 + * leading to delayed download on UIScrollView deceleration for instance.
  24 + */
  25 + SDWebImageLowPriority = 1 << 1,
  26 +
  27 + /**
  28 + * This flag disables on-disk caching
  29 + */
  30 + SDWebImageCacheMemoryOnly = 1 << 2,
  31 +
  32 + /**
  33 + * This flag enables progressive download, the image is displayed progressively during download as a browser would do.
  34 + * By default, the image is only displayed once completely downloaded.
  35 + */
  36 + SDWebImageProgressiveDownload = 1 << 3,
  37 +
  38 + /**
  39 + * Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed.
  40 + * The disk caching will be handled by NSURLCache instead of SDWebImage leading to slight performance degradation.
  41 + * This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics.
  42 + * If a cached image is refreshed, the completion block is called once with the cached image and again with the final image.
  43 + *
  44 + * Use this flag only if you can't make your URLs static with embedded cache busting parameter.
  45 + */
  46 + SDWebImageRefreshCached = 1 << 4,
  47 +
  48 + /**
  49 + * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for
  50 + * extra time in background to let the request finish. If the background task expires the operation will be cancelled.
  51 + */
  52 + SDWebImageContinueInBackground = 1 << 5,
  53 +
  54 + /**
  55 + * Handles cookies stored in NSHTTPCookieStore by setting
  56 + * NSMutableURLRequest.HTTPShouldHandleCookies = YES;
  57 + */
  58 + SDWebImageHandleCookies = 1 << 6,
  59 +
  60 + /**
  61 + * Enable to allow untrusted SSL certificates.
  62 + * Useful for testing purposes. Use with caution in production.
  63 + */
  64 + SDWebImageAllowInvalidSSLCertificates = 1 << 7,
  65 +
  66 + /**
  67 + * By default, images are loaded in the order in which they were queued. This flag moves them to
  68 + * the front of the queue.
  69 + */
  70 + SDWebImageHighPriority = 1 << 8,
  71 +
  72 + /**
  73 + * By default, placeholder images are loaded while the image is loading. This flag will delay the loading
  74 + * of the placeholder image until after the image has finished loading.
  75 + */
  76 + SDWebImageDelayPlaceholder = 1 << 9,
  77 +
  78 + /**
  79 + * We usually don't call transformDownloadedImage delegate method on animated images,
  80 + * as most transformation code would mangle it.
  81 + * Use this flag to transform them anyway.
  82 + */
  83 + SDWebImageTransformAnimatedImage = 1 << 10,
  84 +
  85 + /**
  86 + * By default, image is added to the imageView after download. But in some cases, we want to
  87 + * have the hand before setting the image (apply a filter or add it with cross-fade animation for instance)
  88 + * Use this flag if you want to manually set the image in the completion when success
  89 + */
  90 + SDWebImageAvoidAutoSetImage = 1 << 11
  91 +};
  92 +
  93 +typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL);
  94 +
  95 +typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL);
  96 +
  97 +typedef NSString *(^SDWebImageCacheKeyFilterBlock)(NSURL *url);
  98 +
  99 +
  100 +@class SDWebImageManager;
  101 +
  102 +@protocol SDWebImageManagerDelegate <NSObject>
  103 +
  104 +@optional
  105 +
  106 +/**
  107 + * Controls which image should be downloaded when the image is not found in the cache.
  108 + *
  109 + * @param imageManager The current `SDWebImageManager`
  110 + * @param imageURL The url of the image to be downloaded
  111 + *
  112 + * @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied.
  113 + */
  114 +- (BOOL)imageManager:(SDWebImageManager *)imageManager shouldDownloadImageForURL:(NSURL *)imageURL;
  115 +
  116 +/**
  117 + * Allows to transform the image immediately after it has been downloaded and just before to cache it on disk and memory.
  118 + * NOTE: This method is called from a global queue in order to not to block the main thread.
  119 + *
  120 + * @param imageManager The current `SDWebImageManager`
  121 + * @param image The image to transform
  122 + * @param imageURL The url of the image to transform
  123 + *
  124 + * @return The transformed image object.
  125 + */
  126 +- (UIImage *)imageManager:(SDWebImageManager *)imageManager transformDownloadedImage:(UIImage *)image withURL:(NSURL *)imageURL;
  127 +
  128 +@end
  129 +
  130 +/**
  131 + * The SDWebImageManager is the class behind the UIImageView+WebCache category and likes.
  132 + * It ties the asynchronous downloader (SDWebImageDownloader) with the image cache store (SDImageCache).
  133 + * You can use this class directly to benefit from web image downloading with caching in another context than
  134 + * a UIView.
  135 + *
  136 + * Here is a simple example of how to use SDWebImageManager:
  137 + *
  138 + * @code
  139 +
  140 +SDWebImageManager *manager = [SDWebImageManager sharedManager];
  141 +[manager downloadImageWithURL:imageURL
  142 + options:0
  143 + progress:nil
  144 + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
  145 + if (image) {
  146 + // do something with image
  147 + }
  148 + }];
  149 +
  150 + * @endcode
  151 + */
  152 +@interface SDWebImageManager : NSObject
  153 +
  154 +@property (weak, nonatomic) id <SDWebImageManagerDelegate> delegate;
  155 +
  156 +@property (strong, nonatomic, readonly) SDImageCache *imageCache;
  157 +@property (strong, nonatomic, readonly) SDWebImageDownloader *imageDownloader;
  158 +
  159 +/**
  160 + * The cache filter is a block used each time SDWebImageManager need to convert an URL into a cache key. This can
  161 + * be used to remove dynamic part of an image URL.
  162 + *
  163 + * The following example sets a filter in the application delegate that will remove any query-string from the
  164 + * URL before to use it as a cache key:
  165 + *
  166 + * @code
  167 +
  168 +[[SDWebImageManager sharedManager] setCacheKeyFilter:^(NSURL *url) {
  169 + url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path];
  170 + return [url absoluteString];
  171 +}];
  172 +
  173 + * @endcode
  174 + */
  175 +@property (nonatomic, copy) SDWebImageCacheKeyFilterBlock cacheKeyFilter;
  176 +
  177 +/**
  178 + * Returns global SDWebImageManager instance.
  179 + *
  180 + * @return SDWebImageManager shared instance
  181 + */
  182 ++ (SDWebImageManager *)sharedManager;
  183 +
  184 +/**
  185 + * Allows to specify instance of cache and image downloader used with image manager.
  186 + * @return new instance of `SDWebImageManager` with specified cache and downloader.
  187 + */
  188 +- (instancetype)initWithCache:(SDImageCache *)cache downloader:(SDWebImageDownloader *)downloader;
  189 +
  190 +/**
  191 + * Downloads the image at the given URL if not present in cache or return the cached version otherwise.
  192 + *
  193 + * @param url The URL to the image
  194 + * @param options A mask to specify options to use for this request
  195 + * @param progressBlock A block called while image is downloading
  196 + * @param completedBlock A block called when operation has been completed.
  197 + *
  198 + * This parameter is required.
  199 + *
  200 + * This block has no return value and takes the requested UIImage as first parameter.
  201 + * In case of error the image parameter is nil and the second parameter may contain an NSError.
  202 + *
  203 + * The third parameter is an `SDImageCacheType` enum indicating if the image was retrieved from the local cache
  204 + * or from the memory cache or from the network.
  205 + *
  206 + * The last parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is
  207 + * downloading. This block is thus called repeatedly with a partial image. When image is fully downloaded, the
  208 + * block is called a last time with the full image and the last parameter set to YES.
  209 + *
  210 + * @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation
  211 + */
  212 +- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
  213 + options:(SDWebImageOptions)options
  214 + progress:(SDWebImageDownloaderProgressBlock)progressBlock
  215 + completed:(SDWebImageCompletionWithFinishedBlock)completedBlock;
  216 +
  217 +/**
  218 + * Saves image to cache for given URL
  219 + *
  220 + * @param image The image to cache
  221 + * @param url The URL to the image
  222 + *
  223 + */
  224 +
  225 +- (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url;
  226 +
  227 +/**
  228 + * Cancel all current operations
  229 + */
  230 +- (void)cancelAll;
  231 +
  232 +/**
  233 + * Check one or more operations running
  234 + */
  235 +- (BOOL)isRunning;
  236 +
  237 +/**
  238 + * Check if image has already been cached
  239 + *
  240 + * @param url image url
  241 + *
  242 + * @return if the image was already cached
  243 + */
  244 +- (BOOL)cachedImageExistsForURL:(NSURL *)url;
  245 +
  246 +/**
  247 + * Check if image has already been cached on disk only
  248 + *
  249 + * @param url image url
  250 + *
  251 + * @return if the image was already cached (disk only)
  252 + */
  253 +- (BOOL)diskImageExistsForURL:(NSURL *)url;
  254 +
  255 +/**
  256 + * Async check if image has already been cached
  257 + *
  258 + * @param url image url
  259 + * @param completionBlock the block to be executed when the check is finished
  260 + *
  261 + * @note the completion block is always executed on the main queue
  262 + */
  263 +- (void)cachedImageExistsForURL:(NSURL *)url
  264 + completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;
  265 +
  266 +/**
  267 + * Async check if image has already been cached on disk only
  268 + *
  269 + * @param url image url
  270 + * @param completionBlock the block to be executed when the check is finished
  271 + *
  272 + * @note the completion block is always executed on the main queue
  273 + */
  274 +- (void)diskImageExistsForURL:(NSURL *)url
  275 + completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;
  276 +
  277 +
  278 +/**
  279 + *Return the cache key for a given URL
  280 + */
  281 +- (NSString *)cacheKeyForURL:(NSURL *)url;
  282 +
  283 +@end
  284 +
  285 +
  286 +#pragma mark - Deprecated
  287 +
  288 +typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionBlock`");
  289 +typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionWithFinishedBlock`");
  290 +
  291 +
  292 +@interface SDWebImageManager (Deprecated)
  293 +
  294 +/**
  295 + * Downloads the image at the given URL if not present in cache or return the cached version otherwise.
  296 + *
  297 + * @deprecated This method has been deprecated. Use `downloadImageWithURL:options:progress:completed:`
  298 + */
  299 +- (id <SDWebImageOperation>)downloadWithURL:(NSURL *)url
  300 + options:(SDWebImageOptions)options
  301 + progress:(SDWebImageDownloaderProgressBlock)progressBlock
  302 + completed:(SDWebImageCompletedWithFinishedBlock)completedBlock __deprecated_msg("Method deprecated. Use `downloadImageWithURL:options:progress:completed:`");
  303 +
  304 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/SDWebImageManager.m 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import "SDWebImageManager.h"
  10 +#import <objc/message.h>
  11 +
  12 +@interface SDWebImageCombinedOperation : NSObject <SDWebImageOperation>
  13 +
  14 +@property (assign, nonatomic, getter = isCancelled) BOOL cancelled;
  15 +@property (copy, nonatomic) SDWebImageNoParamsBlock cancelBlock;
  16 +@property (strong, nonatomic) NSOperation *cacheOperation;
  17 +
  18 +@end
  19 +
  20 +@interface SDWebImageManager ()
  21 +
  22 +@property (strong, nonatomic, readwrite) SDImageCache *imageCache;
  23 +@property (strong, nonatomic, readwrite) SDWebImageDownloader *imageDownloader;
  24 +@property (strong, nonatomic) NSMutableSet *failedURLs;
  25 +@property (strong, nonatomic) NSMutableArray *runningOperations;
  26 +
  27 +@end
  28 +
  29 +@implementation SDWebImageManager
  30 +
  31 ++ (id)sharedManager {
  32 + static dispatch_once_t once;
  33 + static id instance;
  34 + dispatch_once(&once, ^{
  35 + instance = [self new];
  36 + });
  37 + return instance;
  38 +}
  39 +
  40 +- (instancetype)init {
  41 + SDImageCache *cache = [SDImageCache sharedImageCache];
  42 + SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
  43 + return [self initWithCache:cache downloader:downloader];
  44 +}
  45 +
  46 +- (instancetype)initWithCache:(SDImageCache *)cache downloader:(SDWebImageDownloader *)downloader {
  47 + if ((self = [super init])) {
  48 + _imageCache = cache;
  49 + _imageDownloader = downloader;
  50 + _failedURLs = [NSMutableSet new];
  51 + _runningOperations = [NSMutableArray new];
  52 + }
  53 + return self;
  54 +}
  55 +
  56 +- (NSString *)cacheKeyForURL:(NSURL *)url {
  57 + if (!url) {
  58 + return @"";
  59 + }
  60 +
  61 + if (self.cacheKeyFilter) {
  62 + return self.cacheKeyFilter(url);
  63 + } else {
  64 + return [url absoluteString];
  65 + }
  66 +}
  67 +
  68 +- (BOOL)cachedImageExistsForURL:(NSURL *)url {
  69 + NSString *key = [self cacheKeyForURL:url];
  70 + if ([self.imageCache imageFromMemoryCacheForKey:key] != nil) return YES;
  71 + return [self.imageCache diskImageExistsWithKey:key];
  72 +}
  73 +
  74 +- (BOOL)diskImageExistsForURL:(NSURL *)url {
  75 + NSString *key = [self cacheKeyForURL:url];
  76 + return [self.imageCache diskImageExistsWithKey:key];
  77 +}
  78 +
  79 +- (void)cachedImageExistsForURL:(NSURL *)url
  80 + completion:(SDWebImageCheckCacheCompletionBlock)completionBlock {
  81 + NSString *key = [self cacheKeyForURL:url];
  82 +
  83 + BOOL isInMemoryCache = ([self.imageCache imageFromMemoryCacheForKey:key] != nil);
  84 +
  85 + if (isInMemoryCache) {
  86 + // making sure we call the completion block on the main queue
  87 + dispatch_async(dispatch_get_main_queue(), ^{
  88 + if (completionBlock) {
  89 + completionBlock(YES);
  90 + }
  91 + });
  92 + return;
  93 + }
  94 +
  95 + [self.imageCache diskImageExistsWithKey:key completion:^(BOOL isInDiskCache) {
  96 + // the completion block of checkDiskCacheForImageWithKey:completion: is always called on the main queue, no need to further dispatch
  97 + if (completionBlock) {
  98 + completionBlock(isInDiskCache);
  99 + }
  100 + }];
  101 +}
  102 +
  103 +- (void)diskImageExistsForURL:(NSURL *)url
  104 + completion:(SDWebImageCheckCacheCompletionBlock)completionBlock {
  105 + NSString *key = [self cacheKeyForURL:url];
  106 +
  107 + [self.imageCache diskImageExistsWithKey:key completion:^(BOOL isInDiskCache) {
  108 + // the completion block of checkDiskCacheForImageWithKey:completion: is always called on the main queue, no need to further dispatch
  109 + if (completionBlock) {
  110 + completionBlock(isInDiskCache);
  111 + }
  112 + }];
  113 +}
  114 +
  115 +- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
  116 + options:(SDWebImageOptions)options
  117 + progress:(SDWebImageDownloaderProgressBlock)progressBlock
  118 + completed:(SDWebImageCompletionWithFinishedBlock)completedBlock {
  119 + // Invoking this method without a completedBlock is pointless
  120 + NSAssert(completedBlock != nil, @"If you mean to prefetch the image, use -[SDWebImagePrefetcher prefetchURLs] instead");
  121 +
  122 + // Very common mistake is to send the URL using NSString object instead of NSURL. For some strange reason, XCode won't
  123 + // throw any warning for this type mismatch. Here we failsafe this error by allowing URLs to be passed as NSString.
  124 + if ([url isKindOfClass:NSString.class]) {
  125 + url = [NSURL URLWithString:(NSString *)url];
  126 + }
  127 +
  128 + // Prevents app crashing on argument type error like sending NSNull instead of NSURL
  129 + if (![url isKindOfClass:NSURL.class]) {
  130 + url = nil;
  131 + }
  132 +
  133 + __block SDWebImageCombinedOperation *operation = [SDWebImageCombinedOperation new];
  134 + __weak SDWebImageCombinedOperation *weakOperation = operation;
  135 +
  136 + BOOL isFailedUrl = NO;
  137 + @synchronized (self.failedURLs) {
  138 + isFailedUrl = [self.failedURLs containsObject:url];
  139 + }
  140 +
  141 + if (url.absoluteString.length == 0 || (!(options & SDWebImageRetryFailed) && isFailedUrl)) {
  142 + dispatch_main_sync_safe(^{
  143 + NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil];
  144 + completedBlock(nil, error, SDImageCacheTypeNone, YES, url);
  145 + });
  146 + return operation;
  147 + }
  148 +
  149 + @synchronized (self.runningOperations) {
  150 + [self.runningOperations addObject:operation];
  151 + }
  152 + NSString *key = [self cacheKeyForURL:url];
  153 +
  154 + operation.cacheOperation = [self.imageCache queryDiskCacheForKey:key done:^(UIImage *image, SDImageCacheType cacheType) {
  155 + if (operation.isCancelled) {
  156 + @synchronized (self.runningOperations) {
  157 + [self.runningOperations removeObject:operation];
  158 + }
  159 +
  160 + return;
  161 + }
  162 +
  163 + if ((!image || options & SDWebImageRefreshCached) && (![self.delegate respondsToSelector:@selector(imageManager:shouldDownloadImageForURL:)] || [self.delegate imageManager:self shouldDownloadImageForURL:url])) {
  164 + if (image && options & SDWebImageRefreshCached) {
  165 + dispatch_main_sync_safe(^{
  166 + // If image was found in the cache but SDWebImageRefreshCached is provided, notify about the cached image
  167 + // AND try to re-download it in order to let a chance to NSURLCache to refresh it from server.
  168 + completedBlock(image, nil, cacheType, YES, url);
  169 + });
  170 + }
  171 +
  172 + // download if no image or requested to refresh anyway, and download allowed by delegate
  173 + SDWebImageDownloaderOptions downloaderOptions = 0;
  174 + if (options & SDWebImageLowPriority) downloaderOptions |= SDWebImageDownloaderLowPriority;
  175 + if (options & SDWebImageProgressiveDownload) downloaderOptions |= SDWebImageDownloaderProgressiveDownload;
  176 + if (options & SDWebImageRefreshCached) downloaderOptions |= SDWebImageDownloaderUseNSURLCache;
  177 + if (options & SDWebImageContinueInBackground) downloaderOptions |= SDWebImageDownloaderContinueInBackground;
  178 + if (options & SDWebImageHandleCookies) downloaderOptions |= SDWebImageDownloaderHandleCookies;
  179 + if (options & SDWebImageAllowInvalidSSLCertificates) downloaderOptions |= SDWebImageDownloaderAllowInvalidSSLCertificates;
  180 + if (options & SDWebImageHighPriority) downloaderOptions |= SDWebImageDownloaderHighPriority;
  181 + if (image && options & SDWebImageRefreshCached) {
  182 + // force progressive off if image already cached but forced refreshing
  183 + downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;
  184 + // ignore image read from NSURLCache if image if cached but force refreshing
  185 + downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
  186 + }
  187 + id <SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished) {
  188 + __strong __typeof(weakOperation) strongOperation = weakOperation;
  189 + if (!strongOperation || strongOperation.isCancelled) {
  190 + // Do nothing if the operation was cancelled
  191 + // See #699 for more details
  192 + // if we would call the completedBlock, there could be a race condition between this block and another completedBlock for the same object, so if this one is called second, we will overwrite the new data
  193 + }
  194 + else if (error) {
  195 + dispatch_main_sync_safe(^{
  196 + if (strongOperation && !strongOperation.isCancelled) {
  197 + completedBlock(nil, error, SDImageCacheTypeNone, finished, url);
  198 + }
  199 + });
  200 +
  201 + if ( error.code != NSURLErrorNotConnectedToInternet
  202 + && error.code != NSURLErrorCancelled
  203 + && error.code != NSURLErrorTimedOut
  204 + && error.code != NSURLErrorInternationalRoamingOff
  205 + && error.code != NSURLErrorDataNotAllowed
  206 + && error.code != NSURLErrorCannotFindHost
  207 + && error.code != NSURLErrorCannotConnectToHost) {
  208 + @synchronized (self.failedURLs) {
  209 + [self.failedURLs addObject:url];
  210 + }
  211 + }
  212 + }
  213 + else {
  214 + if ((options & SDWebImageRetryFailed)) {
  215 + @synchronized (self.failedURLs) {
  216 + [self.failedURLs removeObject:url];
  217 + }
  218 + }
  219 +
  220 + BOOL cacheOnDisk = !(options & SDWebImageCacheMemoryOnly);
  221 +
  222 + if (options & SDWebImageRefreshCached && image && !downloadedImage) {
  223 + // Image refresh hit the NSURLCache cache, do not call the completion block
  224 + }
  225 + else if (downloadedImage && (!downloadedImage.images || (options & SDWebImageTransformAnimatedImage)) && [self.delegate respondsToSelector:@selector(imageManager:transformDownloadedImage:withURL:)]) {
  226 + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  227 + UIImage *transformedImage = [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url];
  228 +
  229 + if (transformedImage && finished) {
  230 + BOOL imageWasTransformed = ![transformedImage isEqual:downloadedImage];
  231 + [self.imageCache storeImage:transformedImage recalculateFromImage:imageWasTransformed imageData:(imageWasTransformed ? nil : data) forKey:key toDisk:cacheOnDisk];
  232 + }
  233 +
  234 + dispatch_main_sync_safe(^{
  235 + if (strongOperation && !strongOperation.isCancelled) {
  236 + completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished, url);
  237 + }
  238 + });
  239 + });
  240 + }
  241 + else {
  242 + if (downloadedImage && finished) {
  243 + [self.imageCache storeImage:downloadedImage recalculateFromImage:NO imageData:data forKey:key toDisk:cacheOnDisk];
  244 + }
  245 +
  246 + dispatch_main_sync_safe(^{
  247 + if (strongOperation && !strongOperation.isCancelled) {
  248 + completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished, url);
  249 + }
  250 + });
  251 + }
  252 + }
  253 +
  254 + if (finished) {
  255 + @synchronized (self.runningOperations) {
  256 + if (strongOperation) {
  257 + [self.runningOperations removeObject:strongOperation];
  258 + }
  259 + }
  260 + }
  261 + }];
  262 + operation.cancelBlock = ^{
  263 + [subOperation cancel];
  264 +
  265 + @synchronized (self.runningOperations) {
  266 + __strong __typeof(weakOperation) strongOperation = weakOperation;
  267 + if (strongOperation) {
  268 + [self.runningOperations removeObject:strongOperation];
  269 + }
  270 + }
  271 + };
  272 + }
  273 + else if (image) {
  274 + dispatch_main_sync_safe(^{
  275 + __strong __typeof(weakOperation) strongOperation = weakOperation;
  276 + if (strongOperation && !strongOperation.isCancelled) {
  277 + completedBlock(image, nil, cacheType, YES, url);
  278 + }
  279 + });
  280 + @synchronized (self.runningOperations) {
  281 + [self.runningOperations removeObject:operation];
  282 + }
  283 + }
  284 + else {
  285 + // Image not in cache and download disallowed by delegate
  286 + dispatch_main_sync_safe(^{
  287 + __strong __typeof(weakOperation) strongOperation = weakOperation;
  288 + if (strongOperation && !weakOperation.isCancelled) {
  289 + completedBlock(nil, nil, SDImageCacheTypeNone, YES, url);
  290 + }
  291 + });
  292 + @synchronized (self.runningOperations) {
  293 + [self.runningOperations removeObject:operation];
  294 + }
  295 + }
  296 + }];
  297 +
  298 + return operation;
  299 +}
  300 +
  301 +- (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url {
  302 + if (image && url) {
  303 + NSString *key = [self cacheKeyForURL:url];
  304 + [self.imageCache storeImage:image forKey:key toDisk:YES];
  305 + }
  306 +}
  307 +
  308 +- (void)cancelAll {
  309 + @synchronized (self.runningOperations) {
  310 + NSArray *copiedOperations = [self.runningOperations copy];
  311 + [copiedOperations makeObjectsPerformSelector:@selector(cancel)];
  312 + [self.runningOperations removeObjectsInArray:copiedOperations];
  313 + }
  314 +}
  315 +
  316 +- (BOOL)isRunning {
  317 + BOOL isRunning = NO;
  318 + @synchronized(self.runningOperations) {
  319 + isRunning = (self.runningOperations.count > 0);
  320 + }
  321 + return isRunning;
  322 +}
  323 +
  324 +@end
  325 +
  326 +
  327 +@implementation SDWebImageCombinedOperation
  328 +
  329 +- (void)setCancelBlock:(SDWebImageNoParamsBlock)cancelBlock {
  330 + // check if the operation is already cancelled, then we just call the cancelBlock
  331 + if (self.isCancelled) {
  332 + if (cancelBlock) {
  333 + cancelBlock();
  334 + }
  335 + _cancelBlock = nil; // don't forget to nil the cancelBlock, otherwise we will get crashes
  336 + } else {
  337 + _cancelBlock = [cancelBlock copy];
  338 + }
  339 +}
  340 +
  341 +- (void)cancel {
  342 + self.cancelled = YES;
  343 + if (self.cacheOperation) {
  344 + [self.cacheOperation cancel];
  345 + self.cacheOperation = nil;
  346 + }
  347 + if (self.cancelBlock) {
  348 + self.cancelBlock();
  349 +
  350 + // TODO: this is a temporary fix to #809.
  351 + // Until we can figure the exact cause of the crash, going with the ivar instead of the setter
  352 +// self.cancelBlock = nil;
  353 + _cancelBlock = nil;
  354 + }
  355 +}
  356 +
  357 +@end
  358 +
  359 +
  360 +@implementation SDWebImageManager (Deprecated)
  361 +
  362 +// deprecated method, uses the non deprecated method
  363 +// adapter for the completion block
  364 +- (id <SDWebImageOperation>)downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock {
  365 + return [self downloadImageWithURL:url
  366 + options:options
  367 + progress:progressBlock
  368 + completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
  369 + if (completedBlock) {
  370 + completedBlock(image, error, cacheType, finished);
  371 + }
  372 + }];
  373 +}
  374 +
  375 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/SDWebImageOperation.h 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +@protocol SDWebImageOperation <NSObject>
  12 +
  13 +- (void)cancel;
  14 +
  15 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/SDWebImagePrefetcher.h 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "SDWebImageManager.h"
  11 +
  12 +@class SDWebImagePrefetcher;
  13 +
  14 +@protocol SDWebImagePrefetcherDelegate <NSObject>
  15 +
  16 +@optional
  17 +
  18 +/**
  19 + * Called when an image was prefetched.
  20 + *
  21 + * @param imagePrefetcher The current image prefetcher
  22 + * @param imageURL The image url that was prefetched
  23 + * @param finishedCount The total number of images that were prefetched (successful or not)
  24 + * @param totalCount The total number of images that were to be prefetched
  25 + */
  26 +- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount;
  27 +
  28 +/**
  29 + * Called when all images are prefetched.
  30 + * @param imagePrefetcher The current image prefetcher
  31 + * @param totalCount The total number of images that were prefetched (whether successful or not)
  32 + * @param skippedCount The total number of images that were skipped
  33 + */
  34 +- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount;
  35 +
  36 +@end
  37 +
  38 +typedef void(^SDWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls);
  39 +typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls);
  40 +
  41 +/**
  42 + * Prefetch some URLs in the cache for future use. Images are downloaded in low priority.
  43 + */
  44 +@interface SDWebImagePrefetcher : NSObject
  45 +
  46 +/**
  47 + * The web image manager
  48 + */
  49 +@property (strong, nonatomic, readonly) SDWebImageManager *manager;
  50 +
  51 +/**
  52 + * Maximum number of URLs to prefetch at the same time. Defaults to 3.
  53 + */
  54 +@property (nonatomic, assign) NSUInteger maxConcurrentDownloads;
  55 +
  56 +/**
  57 + * SDWebImageOptions for prefetcher. Defaults to SDWebImageLowPriority.
  58 + */
  59 +@property (nonatomic, assign) SDWebImageOptions options;
  60 +
  61 +/**
  62 + * Queue options for Prefetcher. Defaults to Main Queue.
  63 + */
  64 +@property (nonatomic, assign) dispatch_queue_t prefetcherQueue;
  65 +
  66 +@property (weak, nonatomic) id <SDWebImagePrefetcherDelegate> delegate;
  67 +
  68 +/**
  69 + * Return the global image prefetcher instance.
  70 + */
  71 ++ (SDWebImagePrefetcher *)sharedImagePrefetcher;
  72 +
  73 +/**
  74 + * Allows you to instantiate a prefetcher with any arbitrary image manager.
  75 + */
  76 +- (id)initWithImageManager:(SDWebImageManager *)manager;
  77 +
  78 +/**
  79 + * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
  80 + * currently one image is downloaded at a time,
  81 + * and skips images for failed downloads and proceed to the next image in the list
  82 + *
  83 + * @param urls list of URLs to prefetch
  84 + */
  85 +- (void)prefetchURLs:(NSArray *)urls;
  86 +
  87 +/**
  88 + * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
  89 + * currently one image is downloaded at a time,
  90 + * and skips images for failed downloads and proceed to the next image in the list
  91 + *
  92 + * @param urls list of URLs to prefetch
  93 + * @param progressBlock block to be called when progress updates;
  94 + * first parameter is the number of completed (successful or not) requests,
  95 + * second parameter is the total number of images originally requested to be prefetched
  96 + * @param completionBlock block to be called when prefetching is completed
  97 + * first param is the number of completed (successful or not) requests,
  98 + * second parameter is the number of skipped requests
  99 + */
  100 +- (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock;
  101 +
  102 +/**
  103 + * Remove and cancel queued list
  104 + */
  105 +- (void)cancelPrefetching;
  106 +
  107 +
  108 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/SDWebImagePrefetcher.m 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import "SDWebImagePrefetcher.h"
  10 +
  11 +@interface SDWebImagePrefetcher ()
  12 +
  13 +@property (strong, nonatomic) SDWebImageManager *manager;
  14 +@property (strong, nonatomic) NSArray *prefetchURLs;
  15 +@property (assign, nonatomic) NSUInteger requestedCount;
  16 +@property (assign, nonatomic) NSUInteger skippedCount;
  17 +@property (assign, nonatomic) NSUInteger finishedCount;
  18 +@property (assign, nonatomic) NSTimeInterval startedTime;
  19 +@property (copy, nonatomic) SDWebImagePrefetcherCompletionBlock completionBlock;
  20 +@property (copy, nonatomic) SDWebImagePrefetcherProgressBlock progressBlock;
  21 +
  22 +@end
  23 +
  24 +@implementation SDWebImagePrefetcher
  25 +
  26 ++ (SDWebImagePrefetcher *)sharedImagePrefetcher {
  27 + static dispatch_once_t once;
  28 + static id instance;
  29 + dispatch_once(&once, ^{
  30 + instance = [self new];
  31 + });
  32 + return instance;
  33 +}
  34 +
  35 +- (id)init {
  36 + return [self initWithImageManager:[SDWebImageManager new]];
  37 +}
  38 +
  39 +- (id)initWithImageManager:(SDWebImageManager *)manager {
  40 + if ((self = [super init])) {
  41 + _manager = manager;
  42 + _options = SDWebImageLowPriority;
  43 + _prefetcherQueue = dispatch_get_main_queue();
  44 + self.maxConcurrentDownloads = 3;
  45 + }
  46 + return self;
  47 +}
  48 +
  49 +- (void)setMaxConcurrentDownloads:(NSUInteger)maxConcurrentDownloads {
  50 + self.manager.imageDownloader.maxConcurrentDownloads = maxConcurrentDownloads;
  51 +}
  52 +
  53 +- (NSUInteger)maxConcurrentDownloads {
  54 + return self.manager.imageDownloader.maxConcurrentDownloads;
  55 +}
  56 +
  57 +- (void)startPrefetchingAtIndex:(NSUInteger)index {
  58 + if (index >= self.prefetchURLs.count) return;
  59 + self.requestedCount++;
  60 + [self.manager downloadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
  61 + if (!finished) return;
  62 + self.finishedCount++;
  63 +
  64 + if (image) {
  65 + if (self.progressBlock) {
  66 + self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
  67 + }
  68 + }
  69 + else {
  70 + if (self.progressBlock) {
  71 + self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
  72 + }
  73 + // Add last failed
  74 + self.skippedCount++;
  75 + }
  76 + if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didPrefetchURL:finishedCount:totalCount:)]) {
  77 + [self.delegate imagePrefetcher:self
  78 + didPrefetchURL:self.prefetchURLs[index]
  79 + finishedCount:self.finishedCount
  80 + totalCount:self.prefetchURLs.count
  81 + ];
  82 + }
  83 + if (self.prefetchURLs.count > self.requestedCount) {
  84 + dispatch_async(self.prefetcherQueue, ^{
  85 + [self startPrefetchingAtIndex:self.requestedCount];
  86 + });
  87 + } else if (self.finishedCount == self.requestedCount) {
  88 + [self reportStatus];
  89 + if (self.completionBlock) {
  90 + self.completionBlock(self.finishedCount, self.skippedCount);
  91 + self.completionBlock = nil;
  92 + }
  93 + self.progressBlock = nil;
  94 + }
  95 + }];
  96 +}
  97 +
  98 +- (void)reportStatus {
  99 + NSUInteger total = [self.prefetchURLs count];
  100 + if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)]) {
  101 + [self.delegate imagePrefetcher:self
  102 + didFinishWithTotalCount:(total - self.skippedCount)
  103 + skippedCount:self.skippedCount
  104 + ];
  105 + }
  106 +}
  107 +
  108 +- (void)prefetchURLs:(NSArray *)urls {
  109 + [self prefetchURLs:urls progress:nil completed:nil];
  110 +}
  111 +
  112 +- (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock {
  113 + [self cancelPrefetching]; // Prevent duplicate prefetch request
  114 + self.startedTime = CFAbsoluteTimeGetCurrent();
  115 + self.prefetchURLs = urls;
  116 + self.completionBlock = completionBlock;
  117 + self.progressBlock = progressBlock;
  118 +
  119 + if (urls.count == 0) {
  120 + if (completionBlock) {
  121 + completionBlock(0,0);
  122 + }
  123 + } else {
  124 + // Starts prefetching from the very first image on the list with the max allowed concurrency
  125 + NSUInteger listCount = self.prefetchURLs.count;
  126 + for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) {
  127 + [self startPrefetchingAtIndex:i];
  128 + }
  129 + }
  130 +}
  131 +
  132 +- (void)cancelPrefetching {
  133 + self.prefetchURLs = nil;
  134 + self.skippedCount = 0;
  135 + self.requestedCount = 0;
  136 + self.finishedCount = 0;
  137 + [self.manager cancelAll];
  138 +}
  139 +
  140 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/UIButton+WebCache.h 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import "SDWebImageCompat.h"
  10 +#import "SDWebImageManager.h"
  11 +
  12 +/**
  13 + * Integrates SDWebImage async downloading and caching of remote images with UIButtonView.
  14 + */
  15 +@interface UIButton (WebCache)
  16 +
  17 +/**
  18 + * Get the current image URL.
  19 + */
  20 +- (NSURL *)sd_currentImageURL;
  21 +
  22 +/**
  23 + * Get the image URL for a control state.
  24 + *
  25 + * @param state Which state you want to know the URL for. The values are described in UIControlState.
  26 + */
  27 +- (NSURL *)sd_imageURLForState:(UIControlState)state;
  28 +
  29 +/**
  30 + * Set the imageView `image` with an `url`.
  31 + *
  32 + * The download is asynchronous and cached.
  33 + *
  34 + * @param url The url for the image.
  35 + * @param state The state that uses the specified title. The values are described in UIControlState.
  36 + */
  37 +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state;
  38 +
  39 +/**
  40 + * Set the imageView `image` with an `url` and a placeholder.
  41 + *
  42 + * The download is asynchronous and cached.
  43 + *
  44 + * @param url The url for the image.
  45 + * @param state The state that uses the specified title. The values are described in UIControlState.
  46 + * @param placeholder The image to be set initially, until the image request finishes.
  47 + * @see sd_setImageWithURL:placeholderImage:options:
  48 + */
  49 +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder;
  50 +
  51 +/**
  52 + * Set the imageView `image` with an `url`, placeholder and custom options.
  53 + *
  54 + * The download is asynchronous and cached.
  55 + *
  56 + * @param url The url for the image.
  57 + * @param state The state that uses the specified title. The values are described in UIControlState.
  58 + * @param placeholder The image to be set initially, until the image request finishes.
  59 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  60 + */
  61 +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
  62 +
  63 +/**
  64 + * Set the imageView `image` with an `url`.
  65 + *
  66 + * The download is asynchronous and cached.
  67 + *
  68 + * @param url The url for the image.
  69 + * @param state The state that uses the specified title. The values are described in UIControlState.
  70 + * @param completedBlock A block called when operation has been completed. This block has no return value
  71 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  72 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  73 + * indicating if the image was retrieved from the local cache or from the network.
  74 + * The fourth parameter is the original image url.
  75 + */
  76 +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock;
  77 +
  78 +/**
  79 + * Set the imageView `image` with an `url`, placeholder.
  80 + *
  81 + * The download is asynchronous and cached.
  82 + *
  83 + * @param url The url for the image.
  84 + * @param state The state that uses the specified title. The values are described in UIControlState.
  85 + * @param placeholder The image to be set initially, until the image request finishes.
  86 + * @param completedBlock A block called when operation has been completed. This block has no return value
  87 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  88 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  89 + * indicating if the image was retrieved from the local cache or from the network.
  90 + * The fourth parameter is the original image url.
  91 + */
  92 +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
  93 +
  94 +/**
  95 + * Set the imageView `image` with an `url`, placeholder and custom options.
  96 + *
  97 + * The download is asynchronous and cached.
  98 + *
  99 + * @param url The url for the image.
  100 + * @param state The state that uses the specified title. The values are described in UIControlState.
  101 + * @param placeholder The image to be set initially, until the image request finishes.
  102 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  103 + * @param completedBlock A block called when operation has been completed. This block has no return value
  104 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  105 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  106 + * indicating if the image was retrieved from the local cache or from the network.
  107 + * The fourth parameter is the original image url.
  108 + */
  109 +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
  110 +
  111 +/**
  112 + * Set the backgroundImageView `image` with an `url`.
  113 + *
  114 + * The download is asynchronous and cached.
  115 + *
  116 + * @param url The url for the image.
  117 + * @param state The state that uses the specified title. The values are described in UIControlState.
  118 + */
  119 +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state;
  120 +
  121 +/**
  122 + * Set the backgroundImageView `image` with an `url` and a placeholder.
  123 + *
  124 + * The download is asynchronous and cached.
  125 + *
  126 + * @param url The url for the image.
  127 + * @param state The state that uses the specified title. The values are described in UIControlState.
  128 + * @param placeholder The image to be set initially, until the image request finishes.
  129 + * @see sd_setImageWithURL:placeholderImage:options:
  130 + */
  131 +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder;
  132 +
  133 +/**
  134 + * Set the backgroundImageView `image` with an `url`, placeholder and custom options.
  135 + *
  136 + * The download is asynchronous and cached.
  137 + *
  138 + * @param url The url for the image.
  139 + * @param state The state that uses the specified title. The values are described in UIControlState.
  140 + * @param placeholder The image to be set initially, until the image request finishes.
  141 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  142 + */
  143 +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
  144 +
  145 +/**
  146 + * Set the backgroundImageView `image` with an `url`.
  147 + *
  148 + * The download is asynchronous and cached.
  149 + *
  150 + * @param url The url for the image.
  151 + * @param state The state that uses the specified title. The values are described in UIControlState.
  152 + * @param completedBlock A block called when operation has been completed. This block has no return value
  153 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  154 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  155 + * indicating if the image was retrieved from the local cache or from the network.
  156 + * The fourth parameter is the original image url.
  157 + */
  158 +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock;
  159 +
  160 +/**
  161 + * Set the backgroundImageView `image` with an `url`, placeholder.
  162 + *
  163 + * The download is asynchronous and cached.
  164 + *
  165 + * @param url The url for the image.
  166 + * @param state The state that uses the specified title. The values are described in UIControlState.
  167 + * @param placeholder The image to be set initially, until the image request finishes.
  168 + * @param completedBlock A block called when operation has been completed. This block has no return value
  169 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  170 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  171 + * indicating if the image was retrieved from the local cache or from the network.
  172 + * The fourth parameter is the original image url.
  173 + */
  174 +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
  175 +
  176 +/**
  177 + * Set the backgroundImageView `image` with an `url`, placeholder and custom options.
  178 + *
  179 + * The download is asynchronous and cached.
  180 + *
  181 + * @param url The url for the image.
  182 + * @param placeholder The image to be set initially, until the image request finishes.
  183 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  184 + * @param completedBlock A block called when operation has been completed. This block has no return value
  185 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  186 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  187 + * indicating if the image was retrieved from the local cache or from the network.
  188 + * The fourth parameter is the original image url.
  189 + */
  190 +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
  191 +
  192 +/**
  193 + * Cancel the current image download
  194 + */
  195 +- (void)sd_cancelImageLoadForState:(UIControlState)state;
  196 +
  197 +/**
  198 + * Cancel the current backgroundImage download
  199 + */
  200 +- (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state;
  201 +
  202 +@end
  203 +
  204 +
  205 +@interface UIButton (WebCacheDeprecated)
  206 +
  207 +- (NSURL *)currentImageURL __deprecated_msg("Use `sd_currentImageURL`");
  208 +- (NSURL *)imageURLForState:(UIControlState)state __deprecated_msg("Use `sd_imageURLForState:`");
  209 +
  210 +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:`");
  211 +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:`");
  212 +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:`");
  213 +
  214 +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:completed:`");
  215 +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:completed:`");
  216 +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:completed:`");
  217 +
  218 +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:`");
  219 +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:`");
  220 +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:`");
  221 +
  222 +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:completed:`");
  223 +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:completed:`");
  224 +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:completed:`");
  225 +
  226 +- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelImageLoadForState:`");
  227 +- (void)cancelBackgroundImageLoadForState:(UIControlState)state __deprecated_msg("Use `sd_cancelBackgroundImageLoadForState:`");
  228 +
  229 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/UIButton+WebCache.m 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import "UIButton+WebCache.h"
  10 +#import "objc/runtime.h"
  11 +#import "UIView+WebCacheOperation.h"
  12 +
  13 +static char imageURLStorageKey;
  14 +
  15 +@implementation UIButton (WebCache)
  16 +
  17 +- (NSURL *)sd_currentImageURL {
  18 + NSURL *url = self.imageURLStorage[@(self.state)];
  19 +
  20 + if (!url) {
  21 + url = self.imageURLStorage[@(UIControlStateNormal)];
  22 + }
  23 +
  24 + return url;
  25 +}
  26 +
  27 +- (NSURL *)sd_imageURLForState:(UIControlState)state {
  28 + return self.imageURLStorage[@(state)];
  29 +}
  30 +
  31 +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state {
  32 + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
  33 +}
  34 +
  35 +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
  36 + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
  37 +}
  38 +
  39 +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
  40 + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
  41 +}
  42 +
  43 +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock {
  44 + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
  45 +}
  46 +
  47 +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
  48 + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
  49 +}
  50 +
  51 +- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
  52 +
  53 + [self setImage:placeholder forState:state];
  54 + [self sd_cancelImageLoadForState:state];
  55 +
  56 + if (!url) {
  57 + [self.imageURLStorage removeObjectForKey:@(state)];
  58 +
  59 + dispatch_main_async_safe(^{
  60 + if (completedBlock) {
  61 + NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
  62 + completedBlock(nil, error, SDImageCacheTypeNone, url);
  63 + }
  64 + });
  65 +
  66 + return;
  67 + }
  68 +
  69 + self.imageURLStorage[@(state)] = url;
  70 +
  71 + __weak __typeof(self)wself = self;
  72 + id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
  73 + if (!wself) return;
  74 + dispatch_main_sync_safe(^{
  75 + __strong UIButton *sself = wself;
  76 + if (!sself) return;
  77 + if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock)
  78 + {
  79 + completedBlock(image, error, cacheType, url);
  80 + return;
  81 + }
  82 + else if (image) {
  83 + [sself setImage:image forState:state];
  84 + }
  85 + if (completedBlock && finished) {
  86 + completedBlock(image, error, cacheType, url);
  87 + }
  88 + });
  89 + }];
  90 + [self sd_setImageLoadOperation:operation forState:state];
  91 +}
  92 +
  93 +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
  94 + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
  95 +}
  96 +
  97 +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
  98 + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
  99 +}
  100 +
  101 +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
  102 + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
  103 +}
  104 +
  105 +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock {
  106 + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
  107 +}
  108 +
  109 +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
  110 + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
  111 +}
  112 +
  113 +- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
  114 + [self sd_cancelBackgroundImageLoadForState:state];
  115 +
  116 + [self setBackgroundImage:placeholder forState:state];
  117 +
  118 + if (url) {
  119 + __weak __typeof(self)wself = self;
  120 + id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
  121 + if (!wself) return;
  122 + dispatch_main_sync_safe(^{
  123 + __strong UIButton *sself = wself;
  124 + if (!sself) return;
  125 + if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock)
  126 + {
  127 + completedBlock(image, error, cacheType, url);
  128 + return;
  129 + }
  130 + else if (image) {
  131 + [sself setBackgroundImage:image forState:state];
  132 + }
  133 + if (completedBlock && finished) {
  134 + completedBlock(image, error, cacheType, url);
  135 + }
  136 + });
  137 + }];
  138 + [self sd_setBackgroundImageLoadOperation:operation forState:state];
  139 + } else {
  140 + dispatch_main_async_safe(^{
  141 + NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
  142 + if (completedBlock) {
  143 + completedBlock(nil, error, SDImageCacheTypeNone, url);
  144 + }
  145 + });
  146 + }
  147 +}
  148 +
  149 +- (void)sd_setImageLoadOperation:(id<SDWebImageOperation>)operation forState:(UIControlState)state {
  150 + [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]];
  151 +}
  152 +
  153 +- (void)sd_cancelImageLoadForState:(UIControlState)state {
  154 + [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]];
  155 +}
  156 +
  157 +- (void)sd_setBackgroundImageLoadOperation:(id<SDWebImageOperation>)operation forState:(UIControlState)state {
  158 + [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]];
  159 +}
  160 +
  161 +- (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state {
  162 + [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]];
  163 +}
  164 +
  165 +- (NSMutableDictionary *)imageURLStorage {
  166 + NSMutableDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey);
  167 + if (!storage)
  168 + {
  169 + storage = [NSMutableDictionary dictionary];
  170 + objc_setAssociatedObject(self, &imageURLStorageKey, storage, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  171 + }
  172 +
  173 + return storage;
  174 +}
  175 +
  176 +@end
  177 +
  178 +
  179 +@implementation UIButton (WebCacheDeprecated)
  180 +
  181 +- (NSURL *)currentImageURL {
  182 + return [self sd_currentImageURL];
  183 +}
  184 +
  185 +- (NSURL *)imageURLForState:(UIControlState)state {
  186 + return [self sd_imageURLForState:state];
  187 +}
  188 +
  189 +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state {
  190 + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
  191 +}
  192 +
  193 +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
  194 + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
  195 +}
  196 +
  197 +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
  198 + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
  199 +}
  200 +
  201 +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
  202 + [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  203 + if (completedBlock) {
  204 + completedBlock(image, error, cacheType);
  205 + }
  206 + }];
  207 +}
  208 +
  209 +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
  210 + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  211 + if (completedBlock) {
  212 + completedBlock(image, error, cacheType);
  213 + }
  214 + }];
  215 +}
  216 +
  217 +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
  218 + [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  219 + if (completedBlock) {
  220 + completedBlock(image, error, cacheType);
  221 + }
  222 + }];
  223 +}
  224 +
  225 +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
  226 + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
  227 +}
  228 +
  229 +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
  230 + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
  231 +}
  232 +
  233 +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
  234 + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
  235 +}
  236 +
  237 +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
  238 + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  239 + if (completedBlock) {
  240 + completedBlock(image, error, cacheType);
  241 + }
  242 + }];
  243 +}
  244 +
  245 +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
  246 + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  247 + if (completedBlock) {
  248 + completedBlock(image, error, cacheType);
  249 + }
  250 + }];
  251 +}
  252 +
  253 +- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
  254 + [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  255 + if (completedBlock) {
  256 + completedBlock(image, error, cacheType);
  257 + }
  258 + }];
  259 +}
  260 +
  261 +- (void)cancelCurrentImageLoad {
  262 + // in a backwards compatible manner, cancel for current state
  263 + [self sd_cancelImageLoadForState:self.state];
  264 +}
  265 +
  266 +- (void)cancelBackgroundImageLoadForState:(UIControlState)state {
  267 + [self sd_cancelBackgroundImageLoadForState:state];
  268 +}
  269 +
  270 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/UIImage+GIF.h 0 → 100755
  1 +//
  2 +// UIImage+GIF.h
  3 +// LBGIFImage
  4 +//
  5 +// Created by Laurin Brandner on 06.01.12.
  6 +// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +@interface UIImage (GIF)
  12 +
  13 ++ (UIImage *)sd_animatedGIFNamed:(NSString *)name;
  14 +
  15 ++ (UIImage *)sd_animatedGIFWithData:(NSData *)data;
  16 +
  17 +- (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size;
  18 +
  19 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/UIImage+GIF.m 0 → 100755
  1 +//
  2 +// UIImage+GIF.m
  3 +// LBGIFImage
  4 +//
  5 +// Created by Laurin Brandner on 06.01.12.
  6 +// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
  7 +//
  8 +
  9 +#import "UIImage+GIF.h"
  10 +#import <ImageIO/ImageIO.h>
  11 +
  12 +@implementation UIImage (GIF)
  13 +
  14 ++ (UIImage *)sd_animatedGIFWithData:(NSData *)data {
  15 + if (!data) {
  16 + return nil;
  17 + }
  18 +
  19 + CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
  20 +
  21 + size_t count = CGImageSourceGetCount(source);
  22 +
  23 + UIImage *animatedImage;
  24 +
  25 + if (count <= 1) {
  26 + animatedImage = [[UIImage alloc] initWithData:data];
  27 + }
  28 + else {
  29 + NSMutableArray *images = [NSMutableArray array];
  30 +
  31 + NSTimeInterval duration = 0.0f;
  32 +
  33 + for (size_t i = 0; i < count; i++) {
  34 + CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL);
  35 + if (!image) {
  36 + continue;
  37 + }
  38 +
  39 + duration += [self sd_frameDurationAtIndex:i source:source];
  40 +
  41 + [images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]];
  42 +
  43 + CGImageRelease(image);
  44 + }
  45 +
  46 + if (!duration) {
  47 + duration = (1.0f / 10.0f) * count;
  48 + }
  49 +
  50 + animatedImage = [UIImage animatedImageWithImages:images duration:duration];
  51 + }
  52 +
  53 + CFRelease(source);
  54 +
  55 + return animatedImage;
  56 +}
  57 +
  58 ++ (float)sd_frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source {
  59 + float frameDuration = 0.1f;
  60 + CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil);
  61 + NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties;
  62 + NSDictionary *gifProperties = frameProperties[(NSString *)kCGImagePropertyGIFDictionary];
  63 +
  64 + NSNumber *delayTimeUnclampedProp = gifProperties[(NSString *)kCGImagePropertyGIFUnclampedDelayTime];
  65 + if (delayTimeUnclampedProp) {
  66 + frameDuration = [delayTimeUnclampedProp floatValue];
  67 + }
  68 + else {
  69 +
  70 + NSNumber *delayTimeProp = gifProperties[(NSString *)kCGImagePropertyGIFDelayTime];
  71 + if (delayTimeProp) {
  72 + frameDuration = [delayTimeProp floatValue];
  73 + }
  74 + }
  75 +
  76 + // Many annoying ads specify a 0 duration to make an image flash as quickly as possible.
  77 + // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify
  78 + // a duration of <= 10 ms. See <rdar://problem/7689300> and <http://webkit.org/b/36082>
  79 + // for more information.
  80 +
  81 + if (frameDuration < 0.011f) {
  82 + frameDuration = 0.100f;
  83 + }
  84 +
  85 + CFRelease(cfFrameProperties);
  86 + return frameDuration;
  87 +}
  88 +
  89 ++ (UIImage *)sd_animatedGIFNamed:(NSString *)name {
  90 + CGFloat scale = [UIScreen mainScreen].scale;
  91 +
  92 + if (scale > 1.0f) {
  93 + NSString *retinaPath = [[NSBundle mainBundle] pathForResource:[name stringByAppendingString:@"@2x"] ofType:@"gif"];
  94 +
  95 + NSData *data = [NSData dataWithContentsOfFile:retinaPath];
  96 +
  97 + if (data) {
  98 + return [UIImage sd_animatedGIFWithData:data];
  99 + }
  100 +
  101 + NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"];
  102 +
  103 + data = [NSData dataWithContentsOfFile:path];
  104 +
  105 + if (data) {
  106 + return [UIImage sd_animatedGIFWithData:data];
  107 + }
  108 +
  109 + return [UIImage imageNamed:name];
  110 + }
  111 + else {
  112 + NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"];
  113 +
  114 + NSData *data = [NSData dataWithContentsOfFile:path];
  115 +
  116 + if (data) {
  117 + return [UIImage sd_animatedGIFWithData:data];
  118 + }
  119 +
  120 + return [UIImage imageNamed:name];
  121 + }
  122 +}
  123 +
  124 +- (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size {
  125 + if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero)) {
  126 + return self;
  127 + }
  128 +
  129 + CGSize scaledSize = size;
  130 + CGPoint thumbnailPoint = CGPointZero;
  131 +
  132 + CGFloat widthFactor = size.width / self.size.width;
  133 + CGFloat heightFactor = size.height / self.size.height;
  134 + CGFloat scaleFactor = (widthFactor > heightFactor) ? widthFactor : heightFactor;
  135 + scaledSize.width = self.size.width * scaleFactor;
  136 + scaledSize.height = self.size.height * scaleFactor;
  137 +
  138 + if (widthFactor > heightFactor) {
  139 + thumbnailPoint.y = (size.height - scaledSize.height) * 0.5;
  140 + }
  141 + else if (widthFactor < heightFactor) {
  142 + thumbnailPoint.x = (size.width - scaledSize.width) * 0.5;
  143 + }
  144 +
  145 + NSMutableArray *scaledImages = [NSMutableArray array];
  146 +
  147 + for (UIImage *image in self.images) {
  148 + UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
  149 +
  150 + [image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)];
  151 + UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
  152 +
  153 + [scaledImages addObject:newImage];
  154 +
  155 + UIGraphicsEndImageContext();
  156 + }
  157 +
  158 + return [UIImage animatedImageWithImages:scaledImages duration:self.duration];
  159 +}
  160 +
  161 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/UIImage+MultiFormat.h 0 → 100755
  1 +//
  2 +// UIImage+MultiFormat.h
  3 +// SDWebImage
  4 +//
  5 +// Created by Olivier Poitrey on 07/06/13.
  6 +// Copyright (c) 2013 Dailymotion. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +@interface UIImage (MultiFormat)
  12 +
  13 ++ (UIImage *)sd_imageWithData:(NSData *)data;
  14 +
  15 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/UIImage+MultiFormat.m 0 → 100755
  1 +//
  2 +// UIImage+MultiFormat.m
  3 +// SDWebImage
  4 +//
  5 +// Created by Olivier Poitrey on 07/06/13.
  6 +// Copyright (c) 2013 Dailymotion. All rights reserved.
  7 +//
  8 +
  9 +#import "UIImage+MultiFormat.h"
  10 +#import "UIImage+GIF.h"
  11 +#import "NSData+ImageContentType.h"
  12 +#import <ImageIO/ImageIO.h>
  13 +
  14 +#ifdef SD_WEBP
  15 +#import "UIImage+WebP.h"
  16 +#endif
  17 +
  18 +@implementation UIImage (MultiFormat)
  19 +
  20 ++ (UIImage *)sd_imageWithData:(NSData *)data {
  21 + if (!data) {
  22 + return nil;
  23 + }
  24 +
  25 + UIImage *image;
  26 + NSString *imageContentType = [NSData sd_contentTypeForImageData:data];
  27 + if ([imageContentType isEqualToString:@"image/gif"]) {
  28 + image = [UIImage sd_animatedGIFWithData:data];
  29 + }
  30 +#ifdef SD_WEBP
  31 + else if ([imageContentType isEqualToString:@"image/webp"])
  32 + {
  33 + image = [UIImage sd_imageWithWebPData:data];
  34 + }
  35 +#endif
  36 + else {
  37 + image = [[UIImage alloc] initWithData:data];
  38 + UIImageOrientation orientation = [self sd_imageOrientationFromImageData:data];
  39 + if (orientation != UIImageOrientationUp) {
  40 + image = [UIImage imageWithCGImage:image.CGImage
  41 + scale:image.scale
  42 + orientation:orientation];
  43 + }
  44 + }
  45 +
  46 +
  47 + return image;
  48 +}
  49 +
  50 +
  51 ++(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData {
  52 + UIImageOrientation result = UIImageOrientationUp;
  53 + CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);
  54 + if (imageSource) {
  55 + CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
  56 + if (properties) {
  57 + CFTypeRef val;
  58 + int exifOrientation;
  59 + val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation);
  60 + if (val) {
  61 + CFNumberGetValue(val, kCFNumberIntType, &exifOrientation);
  62 + result = [self sd_exifOrientationToiOSOrientation:exifOrientation];
  63 + } // else - if it's not set it remains at up
  64 + CFRelease((CFTypeRef) properties);
  65 + } else {
  66 + //NSLog(@"NO PROPERTIES, FAIL");
  67 + }
  68 + CFRelease(imageSource);
  69 + }
  70 + return result;
  71 +}
  72 +
  73 +#pragma mark EXIF orientation tag converter
  74 +// Convert an EXIF image orientation to an iOS one.
  75 +// reference see here: http://sylvana.net/jpegcrop/exif_orientation.html
  76 ++ (UIImageOrientation) sd_exifOrientationToiOSOrientation:(int)exifOrientation {
  77 + UIImageOrientation orientation = UIImageOrientationUp;
  78 + switch (exifOrientation) {
  79 + case 1:
  80 + orientation = UIImageOrientationUp;
  81 + break;
  82 +
  83 + case 3:
  84 + orientation = UIImageOrientationDown;
  85 + break;
  86 +
  87 + case 8:
  88 + orientation = UIImageOrientationLeft;
  89 + break;
  90 +
  91 + case 6:
  92 + orientation = UIImageOrientationRight;
  93 + break;
  94 +
  95 + case 2:
  96 + orientation = UIImageOrientationUpMirrored;
  97 + break;
  98 +
  99 + case 4:
  100 + orientation = UIImageOrientationDownMirrored;
  101 + break;
  102 +
  103 + case 5:
  104 + orientation = UIImageOrientationLeftMirrored;
  105 + break;
  106 +
  107 + case 7:
  108 + orientation = UIImageOrientationRightMirrored;
  109 + break;
  110 + default:
  111 + break;
  112 + }
  113 + return orientation;
  114 +}
  115 +
  116 +
  117 +
  118 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/UIImage+WebP.h 0 → 100755
  1 +//
  2 +// UIImage+WebP.h
  3 +// SDWebImage
  4 +//
  5 +// Created by Olivier Poitrey on 07/06/13.
  6 +// Copyright (c) 2013 Dailymotion. All rights reserved.
  7 +//
  8 +
  9 +#ifdef SD_WEBP
  10 +
  11 +#import <UIKit/UIKit.h>
  12 +
  13 +// Fix for issue #416 Undefined symbols for architecture armv7 since WebP introduction when deploying to device
  14 +void WebPInitPremultiplyNEON(void);
  15 +
  16 +void WebPInitUpsamplersNEON(void);
  17 +
  18 +void VP8DspInitNEON(void);
  19 +
  20 +@interface UIImage (WebP)
  21 +
  22 ++ (UIImage *)sd_imageWithWebPData:(NSData *)data;
  23 +
  24 +@end
  25 +
  26 +#endif
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/UIImage+WebP.m 0 → 100755
  1 +//
  2 +// UIImage+WebP.m
  3 +// SDWebImage
  4 +//
  5 +// Created by Olivier Poitrey on 07/06/13.
  6 +// Copyright (c) 2013 Dailymotion. All rights reserved.
  7 +//
  8 +
  9 +#ifdef SD_WEBP
  10 +#import "UIImage+WebP.h"
  11 +
  12 +#if !COCOAPODS
  13 +#import "webp/decode.h"
  14 +#else
  15 +#import "webp/decode.h"
  16 +#endif
  17 +
  18 +// Callback for CGDataProviderRelease
  19 +static void FreeImageData(void *info, const void *data, size_t size)
  20 +{
  21 + free((void *)data);
  22 +}
  23 +
  24 +@implementation UIImage (WebP)
  25 +
  26 ++ (UIImage *)sd_imageWithWebPData:(NSData *)data {
  27 + WebPDecoderConfig config;
  28 + if (!WebPInitDecoderConfig(&config)) {
  29 + return nil;
  30 + }
  31 +
  32 + if (WebPGetFeatures(data.bytes, data.length, &config.input) != VP8_STATUS_OK) {
  33 + return nil;
  34 + }
  35 +
  36 + config.output.colorspace = config.input.has_alpha ? MODE_rgbA : MODE_RGB;
  37 + config.options.use_threads = 1;
  38 +
  39 + // Decode the WebP image data into a RGBA value array.
  40 + if (WebPDecode(data.bytes, data.length, &config) != VP8_STATUS_OK) {
  41 + return nil;
  42 + }
  43 +
  44 + int width = config.input.width;
  45 + int height = config.input.height;
  46 + if (config.options.use_scaling) {
  47 + width = config.options.scaled_width;
  48 + height = config.options.scaled_height;
  49 + }
  50 +
  51 + // Construct a UIImage from the decoded RGBA value array.
  52 + CGDataProviderRef provider =
  53 + CGDataProviderCreateWithData(NULL, config.output.u.RGBA.rgba, config.output.u.RGBA.size, FreeImageData);
  54 + CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
  55 + CGBitmapInfo bitmapInfo = config.input.has_alpha ? kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast : 0;
  56 + size_t components = config.input.has_alpha ? 4 : 3;
  57 + CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
  58 + CGImageRef imageRef = CGImageCreate(width, height, 8, components * 8, components * width, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
  59 +
  60 + CGColorSpaceRelease(colorSpaceRef);
  61 + CGDataProviderRelease(provider);
  62 +
  63 + UIImage *image = [[UIImage alloc] initWithCGImage:imageRef];
  64 + CGImageRelease(imageRef);
  65 +
  66 + return image;
  67 +}
  68 +
  69 +@end
  70 +
  71 +#if !COCOAPODS
  72 +// Functions to resolve some undefined symbols when using WebP and force_load flag
  73 +void WebPInitPremultiplyNEON(void) {}
  74 +void WebPInitUpsamplersNEON(void) {}
  75 +void VP8DspInitNEON(void) {}
  76 +#endif
  77 +
  78 +#endif
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/UIImageView+HighlightedWebCache.h 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +#import "SDWebImageCompat.h"
  11 +#import "SDWebImageManager.h"
  12 +
  13 +/**
  14 + * Integrates SDWebImage async downloading and caching of remote images with UIImageView for highlighted state.
  15 + */
  16 +@interface UIImageView (HighlightedWebCache)
  17 +
  18 +/**
  19 + * Set the imageView `highlightedImage` with an `url`.
  20 + *
  21 + * The download is asynchronous and cached.
  22 + *
  23 + * @param url The url for the image.
  24 + */
  25 +- (void)sd_setHighlightedImageWithURL:(NSURL *)url;
  26 +
  27 +/**
  28 + * Set the imageView `highlightedImage` with an `url` and custom options.
  29 + *
  30 + * The download is asynchronous and cached.
  31 + *
  32 + * @param url The url for the image.
  33 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  34 + */
  35 +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options;
  36 +
  37 +/**
  38 + * Set the imageView `highlightedImage` with an `url`.
  39 + *
  40 + * The download is asynchronous and cached.
  41 + *
  42 + * @param url The url for the image.
  43 + * @param completedBlock A block called when operation has been completed. This block has no return value
  44 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  45 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  46 + * indicating if the image was retrieved from the local cache or from the network.
  47 + * The fourth parameter is the original image url.
  48 + */
  49 +- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
  50 +
  51 +/**
  52 + * Set the imageView `highlightedImage` with an `url` and custom options.
  53 + *
  54 + * The download is asynchronous and cached.
  55 + *
  56 + * @param url The url for the image.
  57 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  58 + * @param completedBlock A block called when operation has been completed. This block has no return value
  59 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  60 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  61 + * indicating if the image was retrieved from the local cache or from the network.
  62 + * The fourth parameter is the original image url.
  63 + */
  64 +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
  65 +
  66 +/**
  67 + * Set the imageView `highlightedImage` with an `url` and custom options.
  68 + *
  69 + * The download is asynchronous and cached.
  70 + *
  71 + * @param url The url for the image.
  72 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  73 + * @param progressBlock A block called while image is downloading
  74 + * @param completedBlock A block called when operation has been completed. This block has no return value
  75 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  76 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  77 + * indicating if the image was retrieved from the local cache or from the network.
  78 + * The fourth parameter is the original image url.
  79 + */
  80 +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
  81 +
  82 +/**
  83 + * Cancel the current download
  84 + */
  85 +- (void)sd_cancelCurrentHighlightedImageLoad;
  86 +
  87 +@end
  88 +
  89 +
  90 +@interface UIImageView (HighlightedWebCacheDeprecated)
  91 +
  92 +- (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:`");
  93 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:`");
  94 +- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:completed:`");
  95 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:completed:`");
  96 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:progress:completed:`");
  97 +
  98 +- (void)cancelCurrentHighlightedImageLoad __deprecated_msg("Use `sd_cancelCurrentHighlightedImageLoad`");
  99 +
  100 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/UIImageView+HighlightedWebCache.m 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import "UIImageView+HighlightedWebCache.h"
  10 +#import "UIView+WebCacheOperation.h"
  11 +
  12 +#define UIImageViewHighlightedWebCacheOperationKey @"highlightedImage"
  13 +
  14 +@implementation UIImageView (HighlightedWebCache)
  15 +
  16 +- (void)sd_setHighlightedImageWithURL:(NSURL *)url {
  17 + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
  18 +}
  19 +
  20 +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
  21 + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
  22 +}
  23 +
  24 +- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
  25 + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock];
  26 +}
  27 +
  28 +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
  29 + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock];
  30 +}
  31 +
  32 +- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
  33 + [self sd_cancelCurrentHighlightedImageLoad];
  34 +
  35 + if (url) {
  36 + __weak __typeof(self)wself = self;
  37 + id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
  38 + if (!wself) return;
  39 + dispatch_main_sync_safe (^
  40 + {
  41 + if (!wself) return;
  42 + if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock)
  43 + {
  44 + completedBlock(image, error, cacheType, url);
  45 + return;
  46 + }
  47 + else if (image) {
  48 + wself.highlightedImage = image;
  49 + [wself setNeedsLayout];
  50 + }
  51 + if (completedBlock && finished) {
  52 + completedBlock(image, error, cacheType, url);
  53 + }
  54 + });
  55 + }];
  56 + [self sd_setImageLoadOperation:operation forKey:UIImageViewHighlightedWebCacheOperationKey];
  57 + } else {
  58 + dispatch_main_async_safe(^{
  59 + NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
  60 + if (completedBlock) {
  61 + completedBlock(nil, error, SDImageCacheTypeNone, url);
  62 + }
  63 + });
  64 + }
  65 +}
  66 +
  67 +- (void)sd_cancelCurrentHighlightedImageLoad {
  68 + [self sd_cancelImageLoadOperationWithKey:UIImageViewHighlightedWebCacheOperationKey];
  69 +}
  70 +
  71 +@end
  72 +
  73 +
  74 +@implementation UIImageView (HighlightedWebCacheDeprecated)
  75 +
  76 +- (void)setHighlightedImageWithURL:(NSURL *)url {
  77 + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
  78 +}
  79 +
  80 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
  81 + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
  82 +}
  83 +
  84 +- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
  85 + [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  86 + if (completedBlock) {
  87 + completedBlock(image, error, cacheType);
  88 + }
  89 + }];
  90 +}
  91 +
  92 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
  93 + [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  94 + if (completedBlock) {
  95 + completedBlock(image, error, cacheType);
  96 + }
  97 + }];
  98 +}
  99 +
  100 +- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
  101 + [self sd_setHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  102 + if (completedBlock) {
  103 + completedBlock(image, error, cacheType);
  104 + }
  105 + }];
  106 +}
  107 +
  108 +- (void)cancelCurrentHighlightedImageLoad {
  109 + [self sd_cancelCurrentHighlightedImageLoad];
  110 +}
  111 +
  112 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/UIImageView+WebCache.h 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import "SDWebImageCompat.h"
  10 +#import "SDWebImageManager.h"
  11 +
  12 +/**
  13 + * Integrates SDWebImage async downloading and caching of remote images with UIImageView.
  14 + *
  15 + * Usage with a UITableViewCell sub-class:
  16 + *
  17 + * @code
  18 +
  19 +#import <SDWebImage/UIImageView+WebCache.h>
  20 +
  21 +...
  22 +
  23 +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  24 +{
  25 + static NSString *MyIdentifier = @"MyIdentifier";
  26 +
  27 + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
  28 +
  29 + if (cell == nil) {
  30 + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]
  31 + autorelease];
  32 + }
  33 +
  34 + // Here we use the provided sd_setImageWithURL: method to load the web image
  35 + // Ensure you use a placeholder image otherwise cells will be initialized with no image
  36 + [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"]
  37 + placeholderImage:[UIImage imageNamed:@"placeholder"]];
  38 +
  39 + cell.textLabel.text = @"My Text";
  40 + return cell;
  41 +}
  42 +
  43 + * @endcode
  44 + */
  45 +@interface UIImageView (WebCache)
  46 +
  47 +/**
  48 + * Get the current image URL.
  49 + *
  50 + * Note that because of the limitations of categories this property can get out of sync
  51 + * if you use sd_setImage: directly.
  52 + */
  53 +- (NSURL *)sd_imageURL;
  54 +
  55 +/**
  56 + * Set the imageView `image` with an `url`.
  57 + *
  58 + * The download is asynchronous and cached.
  59 + *
  60 + * @param url The url for the image.
  61 + */
  62 +- (void)sd_setImageWithURL:(NSURL *)url;
  63 +
  64 +/**
  65 + * Set the imageView `image` with an `url` and a placeholder.
  66 + *
  67 + * The download is asynchronous and cached.
  68 + *
  69 + * @param url The url for the image.
  70 + * @param placeholder The image to be set initially, until the image request finishes.
  71 + * @see sd_setImageWithURL:placeholderImage:options:
  72 + */
  73 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
  74 +
  75 +/**
  76 + * Set the imageView `image` with an `url`, placeholder and custom options.
  77 + *
  78 + * The download is asynchronous and cached.
  79 + *
  80 + * @param url The url for the image.
  81 + * @param placeholder The image to be set initially, until the image request finishes.
  82 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  83 + */
  84 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
  85 +
  86 +/**
  87 + * Set the imageView `image` with an `url`.
  88 + *
  89 + * The download is asynchronous and cached.
  90 + *
  91 + * @param url The url for the image.
  92 + * @param completedBlock A block called when operation has been completed. This block has no return value
  93 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  94 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  95 + * indicating if the image was retrieved from the local cache or from the network.
  96 + * The fourth parameter is the original image url.
  97 + */
  98 +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
  99 +
  100 +/**
  101 + * Set the imageView `image` with an `url`, placeholder.
  102 + *
  103 + * The download is asynchronous and cached.
  104 + *
  105 + * @param url The url for the image.
  106 + * @param placeholder The image to be set initially, until the image request finishes.
  107 + * @param completedBlock A block called when operation has been completed. This block has no return value
  108 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  109 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  110 + * indicating if the image was retrieved from the local cache or from the network.
  111 + * The fourth parameter is the original image url.
  112 + */
  113 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
  114 +
  115 +/**
  116 + * Set the imageView `image` with an `url`, placeholder and custom options.
  117 + *
  118 + * The download is asynchronous and cached.
  119 + *
  120 + * @param url The url for the image.
  121 + * @param placeholder The image to be set initially, until the image request finishes.
  122 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  123 + * @param completedBlock A block called when operation has been completed. This block has no return value
  124 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  125 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  126 + * indicating if the image was retrieved from the local cache or from the network.
  127 + * The fourth parameter is the original image url.
  128 + */
  129 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
  130 +
  131 +/**
  132 + * Set the imageView `image` with an `url`, placeholder and custom options.
  133 + *
  134 + * The download is asynchronous and cached.
  135 + *
  136 + * @param url The url for the image.
  137 + * @param placeholder The image to be set initially, until the image request finishes.
  138 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  139 + * @param progressBlock A block called while image is downloading
  140 + * @param completedBlock A block called when operation has been completed. This block has no return value
  141 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  142 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  143 + * indicating if the image was retrieved from the local cache or from the network.
  144 + * The fourth parameter is the original image url.
  145 + */
  146 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
  147 +
  148 +/**
  149 + * Set the imageView `image` with an `url` and optionally a placeholder image.
  150 + *
  151 + * The download is asynchronous and cached.
  152 + *
  153 + * @param url The url for the image.
  154 + * @param placeholder The image to be set initially, until the image request finishes.
  155 + * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
  156 + * @param progressBlock A block called while image is downloading
  157 + * @param completedBlock A block called when operation has been completed. This block has no return value
  158 + * and takes the requested UIImage as first parameter. In case of error the image parameter
  159 + * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
  160 + * indicating if the image was retrieved from the local cache or from the network.
  161 + * The fourth parameter is the original image url.
  162 + */
  163 +- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
  164 +
  165 +/**
  166 + * Download an array of images and starts them in an animation loop
  167 + *
  168 + * @param arrayOfURLs An array of NSURL
  169 + */
  170 +- (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs;
  171 +
  172 +/**
  173 + * Cancel the current download
  174 + */
  175 +- (void)sd_cancelCurrentImageLoad;
  176 +
  177 +- (void)sd_cancelCurrentAnimationImagesLoad;
  178 +
  179 +/**
  180 + * Show activity UIActivityIndicatorView
  181 + */
  182 +- (void)setShowActivityIndicatorView:(BOOL)show;
  183 +
  184 +/**
  185 + * set desired UIActivityIndicatorViewStyle
  186 + *
  187 + * @param style The style of the UIActivityIndicatorView
  188 + */
  189 +- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style;
  190 +
  191 +@end
  192 +
  193 +
  194 +@interface UIImageView (WebCacheDeprecated)
  195 +
  196 +- (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`");
  197 +
  198 +- (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`");
  199 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`");
  200 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options`");
  201 +
  202 +- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`");
  203 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`");
  204 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`");
  205 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:progress:completed:`");
  206 +
  207 +- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithPreviousCachedImageWithURL:placeholderImage:options:progress:completed:`");
  208 +
  209 +- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs __deprecated_msg("Use `sd_setAnimationImagesWithURLs:`");
  210 +
  211 +- (void)cancelCurrentArrayLoad __deprecated_msg("Use `sd_cancelCurrentAnimationImagesLoad`");
  212 +
  213 +- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`");
  214 +
  215 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/UIImageView+WebCache.m 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import "UIImageView+WebCache.h"
  10 +#import "objc/runtime.h"
  11 +#import "UIView+WebCacheOperation.h"
  12 +
  13 +static char imageURLKey;
  14 +static char TAG_ACTIVITY_INDICATOR;
  15 +static char TAG_ACTIVITY_STYLE;
  16 +static char TAG_ACTIVITY_SHOW;
  17 +
  18 +@implementation UIImageView (WebCache)
  19 +
  20 +- (void)sd_setImageWithURL:(NSURL *)url {
  21 + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
  22 +}
  23 +
  24 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
  25 + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
  26 +}
  27 +
  28 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
  29 + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
  30 +}
  31 +
  32 +- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
  33 + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock];
  34 +}
  35 +
  36 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
  37 + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock];
  38 +}
  39 +
  40 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
  41 + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock];
  42 +}
  43 +
  44 +- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
  45 + [self sd_cancelCurrentImageLoad];
  46 + objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  47 +
  48 + if (!(options & SDWebImageDelayPlaceholder)) {
  49 + dispatch_main_async_safe(^{
  50 + self.image = placeholder;
  51 + });
  52 + }
  53 +
  54 + if (url) {
  55 +
  56 + // check if activityView is enabled or not
  57 + if ([self showActivityIndicatorView]) {
  58 + [self addActivityIndicator];
  59 + }
  60 +
  61 + __weak __typeof(self)wself = self;
  62 + id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
  63 + [wself removeActivityIndicator];
  64 + if (!wself) return;
  65 + dispatch_main_sync_safe(^{
  66 + if (!wself) return;
  67 + if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock)
  68 + {
  69 + completedBlock(image, error, cacheType, url);
  70 + return;
  71 + }
  72 + else if (image) {
  73 + wself.image = image;
  74 + [wself setNeedsLayout];
  75 + } else {
  76 + if ((options & SDWebImageDelayPlaceholder)) {
  77 + wself.image = placeholder;
  78 + [wself setNeedsLayout];
  79 + }
  80 + }
  81 + if (completedBlock && finished) {
  82 + completedBlock(image, error, cacheType, url);
  83 + }
  84 + });
  85 + }];
  86 + [self sd_setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"];
  87 + } else {
  88 + dispatch_main_async_safe(^{
  89 + [self removeActivityIndicator];
  90 + if (completedBlock) {
  91 + NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
  92 + completedBlock(nil, error, SDImageCacheTypeNone, url);
  93 + }
  94 + });
  95 + }
  96 +}
  97 +
  98 +- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
  99 + NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url];
  100 + UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
  101 +
  102 + [self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock];
  103 +}
  104 +
  105 +- (NSURL *)sd_imageURL {
  106 + return objc_getAssociatedObject(self, &imageURLKey);
  107 +}
  108 +
  109 +- (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs {
  110 + [self sd_cancelCurrentAnimationImagesLoad];
  111 + __weak __typeof(self)wself = self;
  112 +
  113 + NSMutableArray *operationsArray = [[NSMutableArray alloc] init];
  114 +
  115 + for (NSURL *logoImageURL in arrayOfURLs) {
  116 + id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
  117 + if (!wself) return;
  118 + dispatch_main_sync_safe(^{
  119 + __strong UIImageView *sself = wself;
  120 + [sself stopAnimating];
  121 + if (sself && image) {
  122 + NSMutableArray *currentImages = [[sself animationImages] mutableCopy];
  123 + if (!currentImages) {
  124 + currentImages = [[NSMutableArray alloc] init];
  125 + }
  126 + [currentImages addObject:image];
  127 +
  128 + sself.animationImages = currentImages;
  129 + [sself setNeedsLayout];
  130 + }
  131 + [sself startAnimating];
  132 + });
  133 + }];
  134 + [operationsArray addObject:operation];
  135 + }
  136 +
  137 + [self sd_setImageLoadOperation:[NSArray arrayWithArray:operationsArray] forKey:@"UIImageViewAnimationImages"];
  138 +}
  139 +
  140 +- (void)sd_cancelCurrentImageLoad {
  141 + [self sd_cancelImageLoadOperationWithKey:@"UIImageViewImageLoad"];
  142 +}
  143 +
  144 +- (void)sd_cancelCurrentAnimationImagesLoad {
  145 + [self sd_cancelImageLoadOperationWithKey:@"UIImageViewAnimationImages"];
  146 +}
  147 +
  148 +
  149 +#pragma mark -
  150 +- (UIActivityIndicatorView *)activityIndicator {
  151 + return (UIActivityIndicatorView *)objc_getAssociatedObject(self, &TAG_ACTIVITY_INDICATOR);
  152 +}
  153 +
  154 +- (void)setActivityIndicator:(UIActivityIndicatorView *)activityIndicator {
  155 + objc_setAssociatedObject(self, &TAG_ACTIVITY_INDICATOR, activityIndicator, OBJC_ASSOCIATION_RETAIN);
  156 +}
  157 +
  158 +- (void)setShowActivityIndicatorView:(BOOL)show{
  159 + objc_setAssociatedObject(self, &TAG_ACTIVITY_SHOW, [NSNumber numberWithBool:show], OBJC_ASSOCIATION_RETAIN);
  160 +}
  161 +
  162 +- (BOOL)showActivityIndicatorView{
  163 + return [objc_getAssociatedObject(self, &TAG_ACTIVITY_SHOW) boolValue];
  164 +}
  165 +
  166 +- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style{
  167 + objc_setAssociatedObject(self, &TAG_ACTIVITY_STYLE, [NSNumber numberWithInt:style], OBJC_ASSOCIATION_RETAIN);
  168 +}
  169 +
  170 +- (int)getIndicatorStyle{
  171 + return [objc_getAssociatedObject(self, &TAG_ACTIVITY_STYLE) intValue];
  172 +}
  173 +
  174 +- (void)addActivityIndicator {
  175 + if (!self.activityIndicator) {
  176 + self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:[self getIndicatorStyle]];
  177 + self.activityIndicator.translatesAutoresizingMaskIntoConstraints = NO;
  178 +
  179 + dispatch_main_async_safe(^{
  180 + [self addSubview:self.activityIndicator];
  181 +
  182 + [self addConstraint:[NSLayoutConstraint constraintWithItem:self.activityIndicator
  183 + attribute:NSLayoutAttributeCenterX
  184 + relatedBy:NSLayoutRelationEqual
  185 + toItem:self
  186 + attribute:NSLayoutAttributeCenterX
  187 + multiplier:1.0
  188 + constant:0.0]];
  189 + [self addConstraint:[NSLayoutConstraint constraintWithItem:self.activityIndicator
  190 + attribute:NSLayoutAttributeCenterY
  191 + relatedBy:NSLayoutRelationEqual
  192 + toItem:self
  193 + attribute:NSLayoutAttributeCenterY
  194 + multiplier:1.0
  195 + constant:0.0]];
  196 + });
  197 + }
  198 +
  199 + dispatch_main_async_safe(^{
  200 + [self.activityIndicator startAnimating];
  201 + });
  202 +
  203 +}
  204 +
  205 +- (void)removeActivityIndicator {
  206 + if (self.activityIndicator) {
  207 + [self.activityIndicator removeFromSuperview];
  208 + self.activityIndicator = nil;
  209 + }
  210 +}
  211 +
  212 +@end
  213 +
  214 +
  215 +@implementation UIImageView (WebCacheDeprecated)
  216 +
  217 +- (NSURL *)imageURL {
  218 + return [self sd_imageURL];
  219 +}
  220 +
  221 +- (void)setImageWithURL:(NSURL *)url {
  222 + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
  223 +}
  224 +
  225 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
  226 + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
  227 +}
  228 +
  229 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
  230 + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
  231 +}
  232 +
  233 +- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
  234 + [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  235 + if (completedBlock) {
  236 + completedBlock(image, error, cacheType);
  237 + }
  238 + }];
  239 +}
  240 +
  241 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
  242 + [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  243 + if (completedBlock) {
  244 + completedBlock(image, error, cacheType);
  245 + }
  246 + }];
  247 +}
  248 +
  249 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
  250 + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  251 + if (completedBlock) {
  252 + completedBlock(image, error, cacheType);
  253 + }
  254 + }];
  255 +}
  256 +
  257 +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
  258 + [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  259 + if (completedBlock) {
  260 + completedBlock(image, error, cacheType);
  261 + }
  262 + }];
  263 +}
  264 +
  265 +- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
  266 + [self sd_setImageWithPreviousCachedImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:completedBlock];
  267 +}
  268 +
  269 +- (void)cancelCurrentArrayLoad {
  270 + [self sd_cancelCurrentAnimationImagesLoad];
  271 +}
  272 +
  273 +- (void)cancelCurrentImageLoad {
  274 + [self sd_cancelCurrentImageLoad];
  275 +}
  276 +
  277 +- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs {
  278 + [self sd_setAnimationImagesWithURLs:arrayOfURLs];
  279 +}
  280 +
  281 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/UIView+WebCacheOperation.h 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +#import "SDWebImageManager.h"
  11 +
  12 +@interface UIView (WebCacheOperation)
  13 +
  14 +/**
  15 + * Set the image load operation (storage in a UIView based dictionary)
  16 + *
  17 + * @param operation the operation
  18 + * @param key key for storing the operation
  19 + */
  20 +- (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key;
  21 +
  22 +/**
  23 + * Cancel all operations for the current UIView and key
  24 + *
  25 + * @param key key for identifying the operations
  26 + */
  27 +- (void)sd_cancelImageLoadOperationWithKey:(NSString *)key;
  28 +
  29 +/**
  30 + * Just remove the operations corresponding to the current UIView and key without cancelling them
  31 + *
  32 + * @param key key for identifying the operations
  33 + */
  34 +- (void)sd_removeImageLoadOperationWithKey:(NSString *)key;
  35 +
  36 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/SDWebImage/UIView+WebCacheOperation.m 0 → 100755
  1 +/*
  2 + * This file is part of the SDWebImage package.
  3 + * (c) Olivier Poitrey <rs@dailymotion.com>
  4 + *
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + */
  8 +
  9 +#import "UIView+WebCacheOperation.h"
  10 +#import "objc/runtime.h"
  11 +
  12 +static char loadOperationKey;
  13 +
  14 +@implementation UIView (WebCacheOperation)
  15 +
  16 +- (NSMutableDictionary *)operationDictionary {
  17 + NSMutableDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey);
  18 + if (operations) {
  19 + return operations;
  20 + }
  21 + operations = [NSMutableDictionary dictionary];
  22 + objc_setAssociatedObject(self, &loadOperationKey, operations, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  23 + return operations;
  24 +}
  25 +
  26 +- (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key {
  27 + [self sd_cancelImageLoadOperationWithKey:key];
  28 + NSMutableDictionary *operationDictionary = [self operationDictionary];
  29 + [operationDictionary setObject:operation forKey:key];
  30 +}
  31 +
  32 +- (void)sd_cancelImageLoadOperationWithKey:(NSString *)key {
  33 + // Cancel in progress downloader from queue
  34 + NSMutableDictionary *operationDictionary = [self operationDictionary];
  35 + id operations = [operationDictionary objectForKey:key];
  36 + if (operations) {
  37 + if ([operations isKindOfClass:[NSArray class]]) {
  38 + for (id <SDWebImageOperation> operation in operations) {
  39 + if (operation) {
  40 + [operation cancel];
  41 + }
  42 + }
  43 + } else if ([operations conformsToProtocol:@protocol(SDWebImageOperation)]){
  44 + [(id<SDWebImageOperation>) operations cancel];
  45 + }
  46 + [operationDictionary removeObjectForKey:key];
  47 + }
  48 +}
  49 +
  50 +- (void)sd_removeImageLoadOperationWithKey:(NSString *)key {
  51 + NSMutableDictionary *operationDictionary = [self operationDictionary];
  52 + [operationDictionary removeObjectForKey:key];
  53 +}
  54 +
  55 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/UIView+Extension.h 0 → 100644
  1 +//
  2 +// UIView+Extension.h
  3 +// CNLive
  4 +//
  5 +// Created by 雷浩杰 on 15/9/1.
  6 +// Copyright (c) 2015年 雷浩杰. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +@interface UIView (Extension)
  12 +
  13 +@property (assign, nonatomic) CGFloat x;
  14 +@property (assign, nonatomic) CGFloat y;
  15 +@property (assign, nonatomic) CGFloat width;
  16 +@property (assign, nonatomic) CGFloat height;
  17 +@property (assign, nonatomic) CGSize size;
  18 +@property (assign, nonatomic) CGPoint origin;
  19 +@property (nonatomic ,assign) CGFloat left;
  20 +@property (assign, nonatomic) CGFloat right;
  21 +@property (nonatomic ,assign) CGFloat top;
  22 +@property (assign, nonatomic) CGFloat bottom;
  23 +
  24 +@property (nonatomic, assign) CGFloat centerX;
  25 +@property (nonatomic, assign) CGFloat centerY;
  26 +
  27 +
  28 +
  29 +@end
... ...
VLionAdSDKDemo/VLionAdSDKDemo/UIView+Extension.m 0 → 100644
  1 +//
  2 +// UIView+Extension.m
  3 +// CNLive
  4 +//
  5 +// Created by 雷浩杰 on 15/9/1.
  6 +// Copyright (c) 2015年 雷浩杰. All rights reserved.
  7 +//
  8 +
  9 +#import "UIView+Extension.h"
  10 +
  11 +@implementation UIView (Extension)
  12 +
  13 +- (void)setX:(CGFloat)x
  14 +{
  15 + CGRect frame = self.frame;
  16 + frame.origin.x = x;
  17 + self.frame = frame;
  18 +}
  19 +
  20 +- (CGFloat)x
  21 +{
  22 + return self.frame.origin.x;
  23 +}
  24 +
  25 +- (void)setY:(CGFloat)y
  26 +{
  27 + CGRect frame = self.frame;
  28 + frame.origin.y = y;
  29 + self.frame = frame;
  30 +}
  31 +
  32 +- (CGFloat)y
  33 +{
  34 + return self.frame.origin.y;
  35 +}
  36 +
  37 +- (void)setWidth:(CGFloat)width
  38 +{
  39 + CGRect frame = self.frame;
  40 + frame.size.width = width;
  41 + self.frame = frame;
  42 +}
  43 +
  44 +- (CGFloat)width
  45 +{
  46 + return self.frame.size.width;
  47 +}
  48 +
  49 +- (void)setHeight:(CGFloat)height
  50 +{
  51 + CGRect frame = self.frame;
  52 + frame.size.height = height;
  53 + self.frame = frame;
  54 +}
  55 +
  56 +- (CGFloat)height
  57 +{
  58 + return self.frame.size.height;
  59 +}
  60 +
  61 +- (void)setSize:(CGSize)size
  62 +{
  63 + CGRect frame = self.frame;
  64 + frame.size = size;
  65 + self.frame = frame;
  66 +}
  67 +
  68 +- (CGSize)size
  69 +{
  70 + return self.frame.size;
  71 +}
  72 +
  73 +- (void)setOrigin:(CGPoint)origin
  74 +{
  75 + CGRect frame = self.frame;
  76 + frame.origin = origin;
  77 + self.frame = frame;
  78 +}
  79 +
  80 +- (CGPoint)origin
  81 +{
  82 + return self.frame.origin;
  83 +}
  84 +
  85 +- (void)setRight:(CGFloat)right
  86 +{
  87 + CGRect frame = self.frame;
  88 + frame.origin.x = right-frame.size.width;
  89 + self.frame = frame;
  90 +}
  91 +
  92 +- (CGFloat)right
  93 +{
  94 + return self.frame.size.width + self.frame.origin.x;
  95 +}
  96 +
  97 +- (void)setBottom:(CGFloat)bottom
  98 +{
  99 + CGRect frame = self.frame;
  100 + frame.origin.y = bottom-frame.size.height;
  101 + self.frame = frame;
  102 +}
  103 +
  104 +- (CGFloat)bottom
  105 +{
  106 + return self.frame.size.height + self.frame.origin.y;
  107 +}
  108 +
  109 +- (void)setCenterX:(CGFloat)centerX
  110 +{
  111 + CGPoint center = self.center;
  112 + center.x = centerX;
  113 + self.center = center;
  114 +}
  115 +
  116 +- (CGFloat) centerX
  117 +{
  118 + return self.center.x;
  119 +}
  120 +
  121 +- (void)setCenterY:(CGFloat) centerY{
  122 + CGPoint center = self.center;
  123 + center.y = centerY;
  124 + self.center = center;
  125 +}
  126 +
  127 +- (CGFloat) centerY
  128 +{
  129 + return self.center.y;
  130 +}
  131 +
  132 +- (void)setTop:(CGFloat ) top{
  133 + CGRect frame = self.frame;
  134 + frame.origin.y = top;
  135 + self.frame = frame;
  136 +}
  137 +
  138 +- (CGFloat) top
  139 +{
  140 + return CGRectGetMinY(self.frame);
  141 +}
  142 +
  143 +- (void)setLeft:(CGFloat) left{
  144 + CGRect frame = self.frame;
  145 + frame.origin.x = left;
  146 + self.frame = frame;
  147 +}
  148 +
  149 +- (CGFloat) left
  150 +{
  151 + return self.frame.origin.x;
  152 +}
  153 +
  154 +
  155 +@end
... ...