Compare commits
67 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
546a579c62 | |
|
|
4e2a4f091a | |
|
|
17d8690127 | |
|
|
42abd08935 | |
|
|
bb0b84342f | |
|
|
0df12218b7 | |
|
|
2064f28d2f | |
|
|
67f943b0fa | |
|
|
c4dd0eee49 | |
|
|
7684fbd9a7 | |
|
|
3364a981d5 | |
|
|
94c1ec3ed0 | |
|
|
7761afca92 | |
|
|
b059b04fd2 | |
|
|
d1f7694004 | |
|
|
44cb993ee9 | |
|
|
d75bc2765d | |
|
|
8a488d377b | |
|
|
4df3934954 | |
|
|
f6cd50bb65 | |
|
|
c1451f28af | |
|
|
881da8fbe0 | |
|
|
32f4e4d234 | |
|
|
ada86ab939 | |
|
|
9ea1602157 | |
|
|
debc0d4827 | |
|
|
8f4a9dae2d | |
|
|
aecb13d421 | |
|
|
e775b444ef | |
|
|
b4659f7648 | |
|
|
81df4611a1 | |
|
|
22fded56cf | |
|
|
9112170ea3 | |
|
|
795832aadc | |
|
|
fb0cdb6dc4 | |
|
|
b5a504f326 | |
|
|
512c536fcf | |
|
|
d625be8d98 | |
|
|
e9e7edffde | |
|
|
4d295fdaf0 | |
|
|
9aa95e83b9 | |
|
|
842d6aac7b | |
|
|
64382b9100 | |
|
|
8a78586d4e | |
|
|
13cfc5b89a | |
|
|
162174ccc1 | |
|
|
aa1d2905c9 | |
|
|
123f2fd2e6 | |
|
|
503d3aed27 | |
|
|
572f26af27 | |
|
|
6279424b1c | |
|
|
718cbcad3e | |
|
|
3902ed7dec | |
|
|
7913b45fae | |
|
|
56c1ba63ad | |
|
|
e3ba4110a9 | |
|
|
2a29f4a0b7 | |
|
|
260a6f5234 | |
|
|
a32a1775c2 | |
|
|
0384a059c4 | |
|
|
91fcbb635c | |
|
|
a02aa42256 | |
|
|
f773870d2c | |
|
|
ae91053a80 | |
|
|
b00b09e706 | |
|
|
52f7204c34 | |
|
|
917c3d479d |
|
|
@ -0,0 +1 @@
|
||||||
|
*.mdj binary
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
[submodule "Vendors/libwebp"]
|
[submodule "Vendors/libwebp"]
|
||||||
path = Vendors/libwebp
|
path = Vendors/libwebp
|
||||||
url = https://github.com/webmproject/libwebp
|
url = https://github.com/webmproject/libwebp
|
||||||
|
[submodule "Vendors/FLAnimatedImage"]
|
||||||
|
path = Vendors/FLAnimatedImage
|
||||||
|
url = https://github.com/Flipboard/FLAnimatedImage
|
||||||
|
|
|
||||||
33
.travis.yml
33
.travis.yml
|
|
@ -1,27 +1,42 @@
|
||||||
|
|
||||||
language: objective-c
|
language: objective-c
|
||||||
|
|
||||||
osx_image: xcode7.1
|
osx_image: xcode7.1
|
||||||
|
|
||||||
before_install:
|
env:
|
||||||
|
global:
|
||||||
|
- LC_CTYPE=en_US.UTF-8
|
||||||
|
- LANG=en_US.UTF-8
|
||||||
|
|
||||||
- export LANG=en_US.UTF-8
|
|
||||||
|
before_install:
|
||||||
- env
|
- env
|
||||||
- locale
|
- locale
|
||||||
- gem install cocoapods --no-rdoc --no-ri --no-document --quiet
|
- gem install cocoapods --no-rdoc --no-ri --no-document --quiet
|
||||||
|
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet
|
||||||
- pod --version
|
- pod --version
|
||||||
- pod setup --silent > /dev/null
|
- pod setup --silent > /dev/null
|
||||||
- pod repo update --silent
|
- pod repo update --silent
|
||||||
|
- xcpretty --version
|
||||||
|
- xcodebuild -version
|
||||||
|
- xcodebuild -showsdks
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
- set -o pipefail
|
||||||
|
|
||||||
|
- echo Check if the library described by the podspec can be built
|
||||||
- pod lib lint --allow-warnings
|
- pod lib lint --allow-warnings
|
||||||
- xctool -workspace SDWebImage.xcworkspace -scheme 'SDWebImage' -sdk iphonesimulator build
|
|
||||||
- xctool -workspace SDWebImage.xcworkspace -scheme 'SDWebImage+WebP' -sdk iphonesimulator build
|
|
||||||
- xctool -workspace SDWebImage.xcworkspace -scheme 'SDWebImage+MKAnnotation' -sdk iphonesimulator build
|
|
||||||
|
|
||||||
- xctool -workspace SDWebImage.xcworkspace -scheme 'SDWebImage Demo' -sdk iphonesimulator build
|
- echo Build as static library
|
||||||
|
- xcodebuild clean build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage-static' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Debug | xcpretty -c
|
||||||
|
|
||||||
|
- echo Build as dynamic framework
|
||||||
|
- xcodebuild clean build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage iOS' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Debug | xcpretty -c
|
||||||
|
- xcodebuild clean build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage tvOS' -sdk appletvsimulator -configuration Debug | xcpretty -c
|
||||||
|
|
||||||
|
- echo Build the Demo app
|
||||||
|
- xcodebuild clean build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage Demo' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Debug | xcpretty -c
|
||||||
|
|
||||||
|
- echo Run the tests
|
||||||
- pod install --project-directory=Tests
|
- pod install --project-directory=Tests
|
||||||
- xctool -workspace SDWebImage.xcworkspace -scheme 'SDWebImage' -sdk iphonesimulator clean
|
- xcodebuild clean -workspace SDWebImage.xcworkspace -scheme 'SDWebImage-static' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Debug | xcpretty -c
|
||||||
- xctool -workspace SDWebImage.xcworkspace -scheme 'Tests' -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=latest' test
|
- xcodebuild test -workspace SDWebImage.xcworkspace -scheme 'Tests' -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=latest' -configuration Debug | xcpretty -c
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,147 @@
|
||||||
|
#### Using `UIImageView+WebCache` category with `UITableView`
|
||||||
|
|
||||||
|
Just import the `UIImageView+WebCache.h` header, and call the `sd_setImageWithURL:placeholderImage:`
|
||||||
|
method from the `tableView:cellForRowAtIndexPath:` `UITableViewDataSource` method. Everything will be
|
||||||
|
handled for you, from async downloads to caching management.
|
||||||
|
|
||||||
|
```objective-c
|
||||||
|
#import <SDWebImage/UIImageView+WebCache.h>
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||||
|
static NSString *MyIdentifier = @"MyIdentifier";
|
||||||
|
|
||||||
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
|
||||||
|
if (cell == nil) {
|
||||||
|
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
|
||||||
|
reuseIdentifier:MyIdentifier] autorelease];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Here we use the new provided sd_setImageWithURL: method to load the web image
|
||||||
|
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
|
||||||
|
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
|
||||||
|
|
||||||
|
cell.textLabel.text = @"My Text";
|
||||||
|
return cell;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```swift
|
||||||
|
import SDWebImage
|
||||||
|
...
|
||||||
|
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
|
||||||
|
static let myIdentifier = "MyIdentifier"
|
||||||
|
let cell = tableView.dequeueReusableCellWithIdentifier(myIdentifier, forIndexPath: indexPath) as UITableViewCell
|
||||||
|
|
||||||
|
cell.imageView.sd_setImageWithURL(imageUrl, placeholderImage:placeholderImage)
|
||||||
|
return cell
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using blocks
|
||||||
|
|
||||||
|
With blocks, you can be notified about the image download progress and whenever the image retrieval has completed with success or not:
|
||||||
|
|
||||||
|
```objective-c
|
||||||
|
// Here we use the new provided sd_setImageWithURL: method to load the web image
|
||||||
|
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
|
||||||
|
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
|
||||||
|
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
|
... completion code here ...
|
||||||
|
}];
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: neither your success nor failure block will be call if your image request is canceled before completion.
|
||||||
|
|
||||||
|
### Using SDWebImageManager
|
||||||
|
|
||||||
|
The `SDWebImageManager` is the class behind the `UIImageView(WebCache)` category. It ties the asynchronous downloader with the image cache store. You can use this class directly to benefit from web image downloading with caching in another context than a `UIView` (ie: with Cocoa).
|
||||||
|
|
||||||
|
Here is a simple example of how to use `SDWebImageManager`:
|
||||||
|
|
||||||
|
```objective-c
|
||||||
|
SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
|
[manager loadImageWithURL:imageURL
|
||||||
|
options:0
|
||||||
|
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
||||||
|
// progression tracking code
|
||||||
|
}
|
||||||
|
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
|
if (image) {
|
||||||
|
// do something with image
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using Asynchronous Image Downloader Independently
|
||||||
|
|
||||||
|
It's also possible to use the async image downloader independently:
|
||||||
|
|
||||||
|
```objective-c
|
||||||
|
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
|
||||||
|
[downloader downloadImageWithURL:imageURL
|
||||||
|
options:0
|
||||||
|
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
||||||
|
// progression tracking code
|
||||||
|
}
|
||||||
|
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||||
|
if (image && finished) {
|
||||||
|
// do something with image
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using Asynchronous Image Caching Independently
|
||||||
|
|
||||||
|
It is also possible to use the async based image cache store independently. SDImageCache
|
||||||
|
maintains a memory cache and an optional disk cache. Disk cache write operations are performed
|
||||||
|
asynchronous so it doesn't add unnecessary latency to the UI.
|
||||||
|
|
||||||
|
The SDImageCache class provides a singleton instance for convenience but you can create your own
|
||||||
|
instance if you want to create separated cache namespace.
|
||||||
|
|
||||||
|
To lookup the cache, you use the `queryDiskCacheForKey:done:` method. If the method returns nil, it means the cache
|
||||||
|
doesn't currently own the image. You are thus responsible for generating and caching it. The cache
|
||||||
|
key is an application unique identifier for the image to cache. It is generally the absolute URL of
|
||||||
|
the image.
|
||||||
|
|
||||||
|
```objective-c
|
||||||
|
SDImageCache *imageCache = [[SDImageCache alloc] initWithNamespace:@"myNamespace"];
|
||||||
|
[imageCache queryDiskCacheForKey:myCacheKey done:^(UIImage *image) {
|
||||||
|
// image is not nil if image was found
|
||||||
|
}];
|
||||||
|
```
|
||||||
|
|
||||||
|
By default SDImageCache will lookup the disk cache if an image can't be found in the memory cache.
|
||||||
|
You can prevent this from happening by calling the alternative method `imageFromMemoryCacheForKey:`.
|
||||||
|
|
||||||
|
To store an image into the cache, you use the storeImage:forKey: method:
|
||||||
|
|
||||||
|
```objective-c
|
||||||
|
[[SDImageCache sharedImageCache] storeImage:myImage forKey:myCacheKey];
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, the image will be stored in memory cache as well as on disk cache (asynchronously). If
|
||||||
|
you want only the memory cache, use the alternative method storeImage:forKey:toDisk: with a negative
|
||||||
|
third argument.
|
||||||
|
|
||||||
|
### Using cache key filter
|
||||||
|
|
||||||
|
Sometime, you may not want to use the image URL as cache key because part of the URL is dynamic
|
||||||
|
(i.e.: for access control purpose). SDWebImageManager provides a way to set a cache key filter that
|
||||||
|
takes the NSURL as input, and output a cache key NSString.
|
||||||
|
|
||||||
|
The following example sets a filter in the application delegate that will remove any query-string from
|
||||||
|
the URL before to use it as a cache key:
|
||||||
|
|
||||||
|
```objective-c
|
||||||
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||||
|
SDWebImageManager.sharedManager.cacheKeyFilter = ^(NSURL *url) {
|
||||||
|
url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path];
|
||||||
|
return [url absoluteString];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Your app init code...
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
### Installation by cloning the repository
|
||||||
|
|
||||||
|
In order to gain access to all the files from the repository, you should clone it.
|
||||||
|
```
|
||||||
|
git clone --recursive https://github.com/rs/SDWebImage.git
|
||||||
|
```
|
||||||
|
|
||||||
|
... TO BE CHECKED AND DESCRIBED IN DETAIL
|
||||||
|
|
||||||
|
### Add dependencies
|
||||||
|
|
||||||
|
- In you application project app’s target settings, find the "Build Phases" section and open the "Link Binary With Libraries" block:
|
||||||
|
- Click the "+" button again and select the "ImageIO.framework", this is needed by the progressive download feature:
|
||||||
|
|
||||||
|
### Add Linker Flag
|
||||||
|
|
||||||
|
Open the "Build Settings" tab, in the "Linking" section, locate the "Other Linker Flags" setting and add the "-ObjC" flag:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Alternatively, if this causes compilation problems with frameworks that extend optional libraries, such as Parse, RestKit or opencv2, instead of the -ObjC flag use:
|
||||||
|
```
|
||||||
|
-force_load SDWebImage.framework/Versions/Current/SDWebImage
|
||||||
|
```
|
||||||
|
|
||||||
|
If you're using Cocoa Pods and have any frameworks that extend optional libraries, such as Parsen RestKit or opencv2, instead of the -ObjC flag use:
|
||||||
|
```
|
||||||
|
-force_load $(TARGET_BUILD_DIR)/libPods.a
|
||||||
|
```
|
||||||
|
and this:
|
||||||
|
```
|
||||||
|
$(inherited)
|
||||||
|
```
|
||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 224 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
3E75A9861742DBE700DA412D /* CustomPathImages in Resources */ = {isa = PBXBuildFile; fileRef = 3E75A9851742DBE700DA412D /* CustomPathImages */; };
|
3E75A9861742DBE700DA412D /* CustomPathImages in Resources */ = {isa = PBXBuildFile; fileRef = 3E75A9851742DBE700DA412D /* CustomPathImages */; };
|
||||||
|
4317396A1CDFCCE20008FEB9 /* libSDWebImage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D741954841D00390AB0 /* libSDWebImage.a */; };
|
||||||
531041C1157EAC8F00BBABC3 /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 537612E6155ABA44005750A4 /* ImageIO.framework */; };
|
531041C1157EAC8F00BBABC3 /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 537612E6155ABA44005750A4 /* ImageIO.framework */; };
|
||||||
5376129A155AB74D005750A4 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 53761299155AB74D005750A4 /* UIKit.framework */; };
|
5376129A155AB74D005750A4 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 53761299155AB74D005750A4 /* UIKit.framework */; };
|
||||||
5376129C155AB74D005750A4 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5376129B155AB74D005750A4 /* Foundation.framework */; };
|
5376129C155AB74D005750A4 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5376129B155AB74D005750A4 /* Foundation.framework */; };
|
||||||
|
|
@ -22,10 +23,23 @@
|
||||||
53A2B50E155B155A00B12423 /* placeholder@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 53A2B50C155B155A00B12423 /* placeholder@2x.png */; };
|
53A2B50E155B155A00B12423 /* placeholder@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 53A2B50C155B155A00B12423 /* placeholder@2x.png */; };
|
||||||
53EEC18916484553007601E1 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 53EEC18816484553007601E1 /* Default-568h@2x.png */; };
|
53EEC18916484553007601E1 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 53EEC18816484553007601E1 /* Default-568h@2x.png */; };
|
||||||
DA248D44195470FD00390AB0 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 537612E3155ABA3C005750A4 /* MapKit.framework */; };
|
DA248D44195470FD00390AB0 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 537612E3155ABA3C005750A4 /* MapKit.framework */; };
|
||||||
DA248D79195484A500390AB0 /* libSDWebImage+WebP.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D761954841D00390AB0 /* libSDWebImage+WebP.a */; };
|
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
|
4317395F1CDFCC370008FEB9 /* PBXContainerItemProxy */ = {
|
||||||
|
isa = PBXContainerItemProxy;
|
||||||
|
containerPortal = DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */;
|
||||||
|
proxyType = 2;
|
||||||
|
remoteGlobalIDString = 00733A4C1BC487C000A5A117;
|
||||||
|
remoteInfo = "WebImage tvOS";
|
||||||
|
};
|
||||||
|
431739681CDFCCDE0008FEB9 /* PBXContainerItemProxy */ = {
|
||||||
|
isa = PBXContainerItemProxy;
|
||||||
|
containerPortal = DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */;
|
||||||
|
proxyType = 1;
|
||||||
|
remoteGlobalIDString = 53761307155AD0D5005750A4;
|
||||||
|
remoteInfo = SDWebImage;
|
||||||
|
};
|
||||||
43A0FAAE1BDD16AC00B7582B /* PBXContainerItemProxy */ = {
|
43A0FAAE1BDD16AC00B7582B /* PBXContainerItemProxy */ = {
|
||||||
isa = PBXContainerItemProxy;
|
isa = PBXContainerItemProxy;
|
||||||
containerPortal = DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */;
|
containerPortal = DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */;
|
||||||
|
|
@ -33,13 +47,6 @@
|
||||||
remoteGlobalIDString = 4A2CADFF1AB4BB5300B6BC39;
|
remoteGlobalIDString = 4A2CADFF1AB4BB5300B6BC39;
|
||||||
remoteInfo = WebImage;
|
remoteInfo = WebImage;
|
||||||
};
|
};
|
||||||
43AEAFA91D008FEE005B41A8 /* PBXContainerItemProxy */ = {
|
|
||||||
isa = PBXContainerItemProxy;
|
|
||||||
containerPortal = DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */;
|
|
||||||
proxyType = 2;
|
|
||||||
remoteGlobalIDString = 00733A4C1BC487C000A5A117;
|
|
||||||
remoteInfo = "WebImage tvOS";
|
|
||||||
};
|
|
||||||
DA248D731954841D00390AB0 /* PBXContainerItemProxy */ = {
|
DA248D731954841D00390AB0 /* PBXContainerItemProxy */ = {
|
||||||
isa = PBXContainerItemProxy;
|
isa = PBXContainerItemProxy;
|
||||||
containerPortal = DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */;
|
containerPortal = DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */;
|
||||||
|
|
@ -47,20 +54,6 @@
|
||||||
remoteGlobalIDString = 53761325155AD0D5005750A4;
|
remoteGlobalIDString = 53761325155AD0D5005750A4;
|
||||||
remoteInfo = SDWebImage;
|
remoteInfo = SDWebImage;
|
||||||
};
|
};
|
||||||
DA248D751954841D00390AB0 /* PBXContainerItemProxy */ = {
|
|
||||||
isa = PBXContainerItemProxy;
|
|
||||||
containerPortal = DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */;
|
|
||||||
proxyType = 2;
|
|
||||||
remoteGlobalIDString = 537D95C117ECC1FE0097C263;
|
|
||||||
remoteInfo = "SDWebImage+WebP";
|
|
||||||
};
|
|
||||||
DA248D771954841D00390AB0 /* PBXContainerItemProxy */ = {
|
|
||||||
isa = PBXContainerItemProxy;
|
|
||||||
containerPortal = DA248D6C1954841D00390AB0 /* SDWebImage.xcodeproj */;
|
|
||||||
proxyType = 2;
|
|
||||||
remoteGlobalIDString = 531041E0157EAFA400BBABC3;
|
|
||||||
remoteInfo = "SDWebImage+MKAnnotation";
|
|
||||||
};
|
|
||||||
/* End PBXContainerItemProxy section */
|
/* End PBXContainerItemProxy section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
|
@ -93,7 +86,7 @@
|
||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
DA248D79195484A500390AB0 /* libSDWebImage+WebP.a in Frameworks */,
|
4317396A1CDFCCE20008FEB9 /* libSDWebImage.a in Frameworks */,
|
||||||
DA248D44195470FD00390AB0 /* MapKit.framework in Frameworks */,
|
DA248D44195470FD00390AB0 /* MapKit.framework in Frameworks */,
|
||||||
531041C1157EAC8F00BBABC3 /* ImageIO.framework in Frameworks */,
|
531041C1157EAC8F00BBABC3 /* ImageIO.framework in Frameworks */,
|
||||||
5376129A155AB74D005750A4 /* UIKit.framework in Frameworks */,
|
5376129A155AB74D005750A4 /* UIKit.framework in Frameworks */,
|
||||||
|
|
@ -169,10 +162,8 @@
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
DA248D741954841D00390AB0 /* libSDWebImage.a */,
|
DA248D741954841D00390AB0 /* libSDWebImage.a */,
|
||||||
DA248D761954841D00390AB0 /* libSDWebImage+WebP.a */,
|
|
||||||
DA248D781954841D00390AB0 /* libSDWebImage+MKAnnotation.a */,
|
|
||||||
43A0FAAF1BDD16AC00B7582B /* WebImage.framework */,
|
43A0FAAF1BDD16AC00B7582B /* WebImage.framework */,
|
||||||
43AEAFAA1D008FEE005B41A8 /* WebImage.framework */,
|
431739601CDFCC370008FEB9 /* WebImage.framework */,
|
||||||
);
|
);
|
||||||
name = Products;
|
name = Products;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
|
@ -191,6 +182,7 @@
|
||||||
buildRules = (
|
buildRules = (
|
||||||
);
|
);
|
||||||
dependencies = (
|
dependencies = (
|
||||||
|
431739691CDFCCDE0008FEB9 /* PBXTargetDependency */,
|
||||||
);
|
);
|
||||||
name = "SDWebImage Demo";
|
name = "SDWebImage Demo";
|
||||||
productName = "SDWebImage Demo";
|
productName = "SDWebImage Demo";
|
||||||
|
|
@ -230,6 +222,13 @@
|
||||||
/* End PBXProject section */
|
/* End PBXProject section */
|
||||||
|
|
||||||
/* Begin PBXReferenceProxy section */
|
/* Begin PBXReferenceProxy section */
|
||||||
|
431739601CDFCC370008FEB9 /* WebImage.framework */ = {
|
||||||
|
isa = PBXReferenceProxy;
|
||||||
|
fileType = wrapper.framework;
|
||||||
|
path = WebImage.framework;
|
||||||
|
remoteRef = 4317395F1CDFCC370008FEB9 /* PBXContainerItemProxy */;
|
||||||
|
sourceTree = BUILT_PRODUCTS_DIR;
|
||||||
|
};
|
||||||
43A0FAAF1BDD16AC00B7582B /* WebImage.framework */ = {
|
43A0FAAF1BDD16AC00B7582B /* WebImage.framework */ = {
|
||||||
isa = PBXReferenceProxy;
|
isa = PBXReferenceProxy;
|
||||||
fileType = wrapper.framework;
|
fileType = wrapper.framework;
|
||||||
|
|
@ -237,13 +236,6 @@
|
||||||
remoteRef = 43A0FAAE1BDD16AC00B7582B /* PBXContainerItemProxy */;
|
remoteRef = 43A0FAAE1BDD16AC00B7582B /* PBXContainerItemProxy */;
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
sourceTree = BUILT_PRODUCTS_DIR;
|
||||||
};
|
};
|
||||||
43AEAFAA1D008FEE005B41A8 /* WebImage.framework */ = {
|
|
||||||
isa = PBXReferenceProxy;
|
|
||||||
fileType = wrapper.framework;
|
|
||||||
path = WebImage.framework;
|
|
||||||
remoteRef = 43AEAFA91D008FEE005B41A8 /* PBXContainerItemProxy */;
|
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
|
||||||
};
|
|
||||||
DA248D741954841D00390AB0 /* libSDWebImage.a */ = {
|
DA248D741954841D00390AB0 /* libSDWebImage.a */ = {
|
||||||
isa = PBXReferenceProxy;
|
isa = PBXReferenceProxy;
|
||||||
fileType = archive.ar;
|
fileType = archive.ar;
|
||||||
|
|
@ -251,20 +243,6 @@
|
||||||
remoteRef = DA248D731954841D00390AB0 /* PBXContainerItemProxy */;
|
remoteRef = DA248D731954841D00390AB0 /* PBXContainerItemProxy */;
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
sourceTree = BUILT_PRODUCTS_DIR;
|
||||||
};
|
};
|
||||||
DA248D761954841D00390AB0 /* libSDWebImage+WebP.a */ = {
|
|
||||||
isa = PBXReferenceProxy;
|
|
||||||
fileType = archive.ar;
|
|
||||||
path = "libSDWebImage+WebP.a";
|
|
||||||
remoteRef = DA248D751954841D00390AB0 /* PBXContainerItemProxy */;
|
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
|
||||||
};
|
|
||||||
DA248D781954841D00390AB0 /* libSDWebImage+MKAnnotation.a */ = {
|
|
||||||
isa = PBXReferenceProxy;
|
|
||||||
fileType = archive.ar;
|
|
||||||
path = "libSDWebImage+MKAnnotation.a";
|
|
||||||
remoteRef = DA248D771954841D00390AB0 /* PBXContainerItemProxy */;
|
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
|
||||||
};
|
|
||||||
/* End PBXReferenceProxy section */
|
/* End PBXReferenceProxy section */
|
||||||
|
|
||||||
/* Begin PBXResourcesBuildPhase section */
|
/* Begin PBXResourcesBuildPhase section */
|
||||||
|
|
@ -297,6 +275,14 @@
|
||||||
};
|
};
|
||||||
/* End PBXSourcesBuildPhase section */
|
/* End PBXSourcesBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXTargetDependency section */
|
||||||
|
431739691CDFCCDE0008FEB9 /* PBXTargetDependency */ = {
|
||||||
|
isa = PBXTargetDependency;
|
||||||
|
name = SDWebImage;
|
||||||
|
targetProxy = 431739681CDFCCDE0008FEB9 /* PBXContainerItemProxy */;
|
||||||
|
};
|
||||||
|
/* End PBXTargetDependency section */
|
||||||
|
|
||||||
/* Begin PBXVariantGroup section */
|
/* Begin PBXVariantGroup section */
|
||||||
537612B1155AB74D005750A4 /* MasterViewController.xib */ = {
|
537612B1155AB74D005750A4 /* MasterViewController.xib */ = {
|
||||||
isa = PBXVariantGroup;
|
isa = PBXVariantGroup;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
//
|
/*
|
||||||
// AppDelegate.h
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage Demo
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Olivier Poitrey on 09/05/12.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
// Copyright (c) 2012 Dailymotion. All rights reserved.
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
//
|
/*
|
||||||
// AppDelegate.m
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage Demo
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Olivier Poitrey on 09/05/12.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
// Copyright (c) 2012 Dailymotion. All rights reserved.
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#import "AppDelegate.h"
|
#import "AppDelegate.h"
|
||||||
|
|
||||||
|
|
@ -20,10 +20,10 @@
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||||
{
|
{
|
||||||
//Add a custom read-only cache path
|
//Add a custom read-only cache path
|
||||||
NSString *bundledPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"CustomPathImages"];
|
NSString *bundledPath = [[NSBundle mainBundle].resourcePath stringByAppendingPathComponent:@"CustomPathImages"];
|
||||||
[[SDImageCache sharedImageCache] addReadOnlyCachePath:bundledPath];
|
[[SDImageCache sharedImageCache] addReadOnlyCachePath:bundledPath];
|
||||||
|
|
||||||
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
||||||
// Override point for customization after application launch.
|
// Override point for customization after application launch.
|
||||||
|
|
||||||
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
|
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
//
|
/*
|
||||||
// DetailViewController.h
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage Demo
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Olivier Poitrey on 09/05/12.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
// Copyright (c) 2012 Dailymotion. All rights reserved.
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
|
@ -12,6 +12,4 @@
|
||||||
|
|
||||||
@property (strong, nonatomic) NSURL *imageURL;
|
@property (strong, nonatomic) NSURL *imageURL;
|
||||||
|
|
||||||
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,21 @@
|
||||||
//
|
/*
|
||||||
// DetailViewController.m
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage Demo
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Olivier Poitrey on 09/05/12.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
// Copyright (c) 2012 Dailymotion. All rights reserved.
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#import "DetailViewController.h"
|
#import "DetailViewController.h"
|
||||||
#import <SDWebImage/UIImageView+WebCache.h>
|
#import <SDWebImage/UIImageView+WebCache.h>
|
||||||
|
#import <SDWebImage/FLAnimatedImageView+WebCache.h>
|
||||||
|
|
||||||
@interface DetailViewController ()
|
@interface DetailViewController ()
|
||||||
|
|
||||||
|
@property (strong, nonatomic) IBOutlet FLAnimatedImageView *imageView;
|
||||||
|
|
||||||
- (void)configureView;
|
- (void)configureView;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DetailViewController
|
@implementation DetailViewController
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
//
|
/*
|
||||||
// MasterViewController.h
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage Demo
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Olivier Poitrey on 09/05/12.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
// Copyright (c) 2012 Dailymotion. All rights reserved.
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,44 @@
|
||||||
//
|
/*
|
||||||
// MasterViewController.m
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage Demo
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Olivier Poitrey on 09/05/12.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
// Copyright (c) 2012 Dailymotion. All rights reserved.
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#import "MasterViewController.h"
|
#import "MasterViewController.h"
|
||||||
#import <SDWebImage/UIImageView+WebCache.h>
|
#import <SDWebImage/UIImageView+WebCache.h>
|
||||||
#import "DetailViewController.h"
|
#import "DetailViewController.h"
|
||||||
|
#import <SDWebImage/FLAnimatedImageView.h>
|
||||||
|
#import <SDWebImage/FLAnimatedImageView+WebCache.h>
|
||||||
|
|
||||||
|
|
||||||
|
@interface MyCustomTableViewCell : UITableViewCell
|
||||||
|
|
||||||
|
@property (nonatomic, strong) UILabel *customTextLabel;
|
||||||
|
@property (nonatomic, strong) FLAnimatedImageView *customImageView;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation MyCustomTableViewCell
|
||||||
|
|
||||||
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
||||||
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
||||||
|
_customImageView = [[FLAnimatedImageView alloc] initWithFrame:CGRectMake(20.0, 2.0, 60.0, 40.0)];
|
||||||
|
[self.contentView addSubview:_customImageView];
|
||||||
|
_customTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(100.0, 12.0, 200, 20.0)];
|
||||||
|
[self.contentView addSubview:_customTextLabel];
|
||||||
|
|
||||||
|
_customImageView.clipsToBounds = YES;
|
||||||
|
_customImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@interface MasterViewController () {
|
@interface MasterViewController () {
|
||||||
NSMutableArray *_objects;
|
NSMutableArray *_objects;
|
||||||
|
|
@ -19,7 +49,7 @@
|
||||||
|
|
||||||
@synthesize detailViewController = _detailViewController;
|
@synthesize detailViewController = _detailViewController;
|
||||||
|
|
||||||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
|
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
|
||||||
{
|
{
|
||||||
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
||||||
if (self)
|
if (self)
|
||||||
|
|
@ -38,6 +68,7 @@
|
||||||
_objects = [NSMutableArray arrayWithObjects:
|
_objects = [NSMutableArray arrayWithObjects:
|
||||||
@"http://www.httpwatch.com/httpgallery/authentication/authenticatedimage/default.aspx?0.35786508303135633", // requires HTTP auth, used to demo the NTLM auth
|
@"http://www.httpwatch.com/httpgallery/authentication/authenticatedimage/default.aspx?0.35786508303135633", // requires HTTP auth, used to demo the NTLM auth
|
||||||
@"http://assets.sbnation.com/assets/2512203/dogflops.gif",
|
@"http://assets.sbnation.com/assets/2512203/dogflops.gif",
|
||||||
|
@"https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif",
|
||||||
@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp",
|
@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp",
|
||||||
@"http://www.ioncannon.net/wp-content/uploads/2011/06/test9.webp",
|
@"http://www.ioncannon.net/wp-content/uploads/2011/06/test9.webp",
|
||||||
nil];
|
nil];
|
||||||
|
|
@ -79,19 +110,23 @@
|
||||||
{
|
{
|
||||||
static NSString *CellIdentifier = @"Cell";
|
static NSString *CellIdentifier = @"Cell";
|
||||||
|
|
||||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
static UIImage *placeholderImage = nil;
|
||||||
if (cell == nil)
|
if (!placeholderImage) {
|
||||||
{
|
placeholderImage = [UIImage imageNamed:@"placeholder"];
|
||||||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
|
}
|
||||||
|
|
||||||
|
MyCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
||||||
|
if (cell == nil) {
|
||||||
|
cell = [[MyCustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
|
||||||
}
|
}
|
||||||
|
|
||||||
[cell.imageView setShowActivityIndicatorView:YES];
|
[cell.customImageView setShowActivityIndicatorView:YES];
|
||||||
[cell.imageView setIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
[cell.customImageView setIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
||||||
|
|
||||||
cell.textLabel.text = [NSString stringWithFormat:@"Image #%ld", (long)indexPath.row];
|
cell.customTextLabel.text = [NSString stringWithFormat:@"Image #%ld", (long)indexPath.row];
|
||||||
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
|
[cell.customImageView sd_setImageWithURL:[NSURL URLWithString:_objects[indexPath.row]]
|
||||||
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:[_objects objectAtIndex:indexPath.row]]
|
placeholderImage:placeholderImage
|
||||||
placeholderImage:[UIImage imageNamed:@"placeholder"] options:indexPath.row == 0 ? SDWebImageRefreshCached : 0];
|
options:indexPath.row == 0 ? SDWebImageRefreshCached : 0];
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,7 +136,7 @@
|
||||||
{
|
{
|
||||||
self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
|
self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
|
||||||
}
|
}
|
||||||
NSString *largeImageURL = [[_objects objectAtIndex:indexPath.row] stringByReplacingOccurrencesOfString:@"small" withString:@"source"];
|
NSString *largeImageURL = [_objects[indexPath.row] stringByReplacingOccurrencesOfString:@"small" withString:@"source"];
|
||||||
self.detailViewController.imageURL = [NSURL URLWithString:largeImageURL];
|
self.detailViewController.imageURL = [NSURL URLWithString:largeImageURL];
|
||||||
[self.navigationController pushViewController:self.detailViewController animated:YES];
|
[self.navigationController pushViewController:self.detailViewController animated:YES];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,164 +1,28 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
|
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
|
||||||
<data>
|
<dependencies>
|
||||||
<int key="IBDocument.SystemTarget">1296</int>
|
<deployment identifier="iOS"/>
|
||||||
<string key="IBDocument.SystemVersion">11D50b</string>
|
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
|
||||||
<string key="IBDocument.InterfaceBuilderVersion">2182</string>
|
</dependencies>
|
||||||
<string key="IBDocument.AppKitVersion">1138.32</string>
|
<objects>
|
||||||
<string key="IBDocument.HIToolboxVersion">568.00</string>
|
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="DetailViewController">
|
||||||
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
|
<connections>
|
||||||
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
<outlet property="imageView" destination="7" id="8"/>
|
||||||
<string key="NS.object.0">1181</string>
|
<outlet property="view" destination="1" id="3"/>
|
||||||
</object>
|
</connections>
|
||||||
<array key="IBDocument.IntegratedClassDependencies">
|
</placeholder>
|
||||||
<string>IBProxyObject</string>
|
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||||
<string>IBUIView</string>
|
<view contentMode="scaleToFill" id="1">
|
||||||
<string>IBUIImageView</string>
|
<rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
|
||||||
</array>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<array key="IBDocument.PluginDependencies">
|
<subviews>
|
||||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" id="7" customClass="FLAnimatedImageView">
|
||||||
</array>
|
<rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
|
||||||
<object class="NSMutableDictionary" key="IBDocument.Metadata">
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<string key="NS.key.0">PluginDependencyRecalculationVersion</string>
|
</imageView>
|
||||||
<integer value="1" key="NS.object.0"/>
|
</subviews>
|
||||||
</object>
|
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||||
<array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
|
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||||
<object class="IBProxyObject" id="372490531">
|
</view>
|
||||||
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
|
</objects>
|
||||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
</document>
|
||||||
</object>
|
|
||||||
<object class="IBProxyObject" id="975951072">
|
|
||||||
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
|
|
||||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
|
||||||
</object>
|
|
||||||
<object class="IBUIView" id="191373211">
|
|
||||||
<reference key="NSNextResponder"/>
|
|
||||||
<int key="NSvFlags">274</int>
|
|
||||||
<array class="NSMutableArray" key="NSSubviews">
|
|
||||||
<object class="IBUIImageView" id="268130440">
|
|
||||||
<reference key="NSNextResponder" ref="191373211"/>
|
|
||||||
<int key="NSvFlags">274</int>
|
|
||||||
<string key="NSFrameSize">{320, 460}</string>
|
|
||||||
<reference key="NSSuperview" ref="191373211"/>
|
|
||||||
<reference key="NSWindow"/>
|
|
||||||
<string key="NSReuseIdentifierKey">_NS:9</string>
|
|
||||||
<int key="IBUIContentMode">1</int>
|
|
||||||
<bool key="IBUIUserInteractionEnabled">NO</bool>
|
|
||||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
|
||||||
</object>
|
|
||||||
</array>
|
|
||||||
<string key="NSFrame">{{0, 20}, {320, 460}}</string>
|
|
||||||
<reference key="NSSuperview"/>
|
|
||||||
<reference key="NSWindow"/>
|
|
||||||
<object class="NSColor" key="IBUIBackgroundColor">
|
|
||||||
<int key="NSColorSpace">3</int>
|
|
||||||
<bytes key="NSWhite">MQA</bytes>
|
|
||||||
<object class="NSColorSpace" key="NSCustomColorSpace">
|
|
||||||
<int key="NSID">2</int>
|
|
||||||
</object>
|
|
||||||
</object>
|
|
||||||
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
|
|
||||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
|
||||||
</object>
|
|
||||||
</array>
|
|
||||||
<object class="IBObjectContainer" key="IBDocument.Objects">
|
|
||||||
<array class="NSMutableArray" key="connectionRecords">
|
|
||||||
<object class="IBConnectionRecord">
|
|
||||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
|
||||||
<string key="label">view</string>
|
|
||||||
<reference key="source" ref="372490531"/>
|
|
||||||
<reference key="destination" ref="191373211"/>
|
|
||||||
</object>
|
|
||||||
<int key="connectionID">3</int>
|
|
||||||
</object>
|
|
||||||
<object class="IBConnectionRecord">
|
|
||||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
|
||||||
<string key="label">imageView</string>
|
|
||||||
<reference key="source" ref="372490531"/>
|
|
||||||
<reference key="destination" ref="268130440"/>
|
|
||||||
</object>
|
|
||||||
<int key="connectionID">8</int>
|
|
||||||
</object>
|
|
||||||
</array>
|
|
||||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
|
||||||
<array key="orderedObjects">
|
|
||||||
<object class="IBObjectRecord">
|
|
||||||
<int key="objectID">0</int>
|
|
||||||
<array key="object" id="0"/>
|
|
||||||
<reference key="children" ref="1000"/>
|
|
||||||
<nil key="parent"/>
|
|
||||||
</object>
|
|
||||||
<object class="IBObjectRecord">
|
|
||||||
<int key="objectID">1</int>
|
|
||||||
<reference key="object" ref="191373211"/>
|
|
||||||
<array class="NSMutableArray" key="children">
|
|
||||||
<reference ref="268130440"/>
|
|
||||||
</array>
|
|
||||||
<reference key="parent" ref="0"/>
|
|
||||||
</object>
|
|
||||||
<object class="IBObjectRecord">
|
|
||||||
<int key="objectID">-1</int>
|
|
||||||
<reference key="object" ref="372490531"/>
|
|
||||||
<reference key="parent" ref="0"/>
|
|
||||||
<string key="objectName">File's Owner</string>
|
|
||||||
</object>
|
|
||||||
<object class="IBObjectRecord">
|
|
||||||
<int key="objectID">-2</int>
|
|
||||||
<reference key="object" ref="975951072"/>
|
|
||||||
<reference key="parent" ref="0"/>
|
|
||||||
</object>
|
|
||||||
<object class="IBObjectRecord">
|
|
||||||
<int key="objectID">7</int>
|
|
||||||
<reference key="object" ref="268130440"/>
|
|
||||||
<reference key="parent" ref="191373211"/>
|
|
||||||
</object>
|
|
||||||
</array>
|
|
||||||
</object>
|
|
||||||
<dictionary class="NSMutableDictionary" key="flattenedProperties">
|
|
||||||
<string key="-1.CustomClassName">DetailViewController</string>
|
|
||||||
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
|
||||||
<string key="-2.CustomClassName">UIResponder</string>
|
|
||||||
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
|
||||||
<string key="1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
|
||||||
<string key="7.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
|
||||||
</dictionary>
|
|
||||||
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
|
|
||||||
<nil key="activeLocalization"/>
|
|
||||||
<dictionary class="NSMutableDictionary" key="localizations"/>
|
|
||||||
<nil key="sourceID"/>
|
|
||||||
<int key="maxID">8</int>
|
|
||||||
</object>
|
|
||||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
|
||||||
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
|
|
||||||
<object class="IBPartialClassDescription">
|
|
||||||
<string key="className">DetailViewController</string>
|
|
||||||
<string key="superclassName">UIViewController</string>
|
|
||||||
<object class="NSMutableDictionary" key="outlets">
|
|
||||||
<string key="NS.key.0">imageView</string>
|
|
||||||
<string key="NS.object.0">UIImageView</string>
|
|
||||||
</object>
|
|
||||||
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
|
|
||||||
<string key="NS.key.0">imageView</string>
|
|
||||||
<object class="IBToOneOutletInfo" key="NS.object.0">
|
|
||||||
<string key="name">imageView</string>
|
|
||||||
<string key="candidateClassName">UIImageView</string>
|
|
||||||
</object>
|
|
||||||
</object>
|
|
||||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
|
||||||
<string key="majorKey">IBProjectSource</string>
|
|
||||||
<string key="minorKey">./Classes/DetailViewController.h</string>
|
|
||||||
</object>
|
|
||||||
</object>
|
|
||||||
</array>
|
|
||||||
</object>
|
|
||||||
<int key="IBDocument.localizationMode">0</int>
|
|
||||||
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
|
||||||
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
|
|
||||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
|
|
||||||
<real value="1296" key="NS.object.0"/>
|
|
||||||
</object>
|
|
||||||
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
|
|
||||||
<int key="IBDocument.defaultPropertyAccessControl">3</int>
|
|
||||||
<string key="IBCocoaTouchPluginVersion">1181</string>
|
|
||||||
</data>
|
|
||||||
</archive>
|
|
||||||
|
|
|
||||||
|
|
@ -1,139 +1,25 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
|
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
|
||||||
<data>
|
<dependencies>
|
||||||
<int key="IBDocument.SystemTarget">1280</int>
|
<deployment identifier="iOS"/>
|
||||||
<string key="IBDocument.SystemVersion">11C25</string>
|
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
|
||||||
<string key="IBDocument.InterfaceBuilderVersion">1919</string>
|
</dependencies>
|
||||||
<string key="IBDocument.AppKitVersion">1138.11</string>
|
<objects>
|
||||||
<string key="IBDocument.HIToolboxVersion">566.00</string>
|
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MasterViewController">
|
||||||
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
|
<connections>
|
||||||
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
<outlet property="view" destination="2" id="3"/>
|
||||||
<string key="NS.object.0">916</string>
|
</connections>
|
||||||
</object>
|
</placeholder>
|
||||||
<array key="IBDocument.IntegratedClassDependencies">
|
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||||
<string>IBProxyObject</string>
|
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="2">
|
||||||
<string>IBUITableView</string>
|
<rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
|
||||||
</array>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<array key="IBDocument.PluginDependencies">
|
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||||
</array>
|
<connections>
|
||||||
<object class="NSMutableDictionary" key="IBDocument.Metadata">
|
<outlet property="dataSource" destination="-1" id="4"/>
|
||||||
<string key="NS.key.0">PluginDependencyRecalculationVersion</string>
|
<outlet property="delegate" destination="-1" id="5"/>
|
||||||
<integer value="1" key="NS.object.0"/>
|
</connections>
|
||||||
</object>
|
</tableView>
|
||||||
<array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
|
</objects>
|
||||||
<object class="IBProxyObject" id="841351856">
|
</document>
|
||||||
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
|
|
||||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
|
||||||
</object>
|
|
||||||
<object class="IBProxyObject" id="371349661">
|
|
||||||
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
|
|
||||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
|
||||||
</object>
|
|
||||||
<object class="IBUITableView" id="709618507">
|
|
||||||
<reference key="NSNextResponder"/>
|
|
||||||
<int key="NSvFlags">274</int>
|
|
||||||
<string key="NSFrame">{{0, 20}, {320, 460}}</string>
|
|
||||||
<reference key="NSSuperview"/>
|
|
||||||
<reference key="NSWindow"/>
|
|
||||||
<object class="NSColor" key="IBUIBackgroundColor">
|
|
||||||
<int key="NSColorSpace">3</int>
|
|
||||||
<bytes key="NSWhite">MQA</bytes>
|
|
||||||
</object>
|
|
||||||
<bool key="IBUIClipsSubviews">YES</bool>
|
|
||||||
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
|
|
||||||
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
|
||||||
<bool key="IBUIAlwaysBounceVertical">YES</bool>
|
|
||||||
<int key="IBUISeparatorStyle">1</int>
|
|
||||||
<int key="IBUISectionIndexMinimumDisplayRowCount">0</int>
|
|
||||||
<bool key="IBUIShowsSelectionImmediatelyOnTouchBegin">YES</bool>
|
|
||||||
<float key="IBUIRowHeight">44</float>
|
|
||||||
<float key="IBUISectionHeaderHeight">22</float>
|
|
||||||
<float key="IBUISectionFooterHeight">22</float>
|
|
||||||
</object>
|
|
||||||
</array>
|
|
||||||
<object class="IBObjectContainer" key="IBDocument.Objects">
|
|
||||||
<array class="NSMutableArray" key="connectionRecords">
|
|
||||||
<object class="IBConnectionRecord">
|
|
||||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
|
||||||
<string key="label">view</string>
|
|
||||||
<reference key="source" ref="841351856"/>
|
|
||||||
<reference key="destination" ref="709618507"/>
|
|
||||||
</object>
|
|
||||||
<int key="connectionID">3</int>
|
|
||||||
</object>
|
|
||||||
<object class="IBConnectionRecord">
|
|
||||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
|
||||||
<string key="label">dataSource</string>
|
|
||||||
<reference key="source" ref="709618507"/>
|
|
||||||
<reference key="destination" ref="841351856"/>
|
|
||||||
</object>
|
|
||||||
<int key="connectionID">4</int>
|
|
||||||
</object>
|
|
||||||
<object class="IBConnectionRecord">
|
|
||||||
<object class="IBCocoaTouchOutletConnection" key="connection">
|
|
||||||
<string key="label">delegate</string>
|
|
||||||
<reference key="source" ref="709618507"/>
|
|
||||||
<reference key="destination" ref="841351856"/>
|
|
||||||
</object>
|
|
||||||
<int key="connectionID">5</int>
|
|
||||||
</object>
|
|
||||||
</array>
|
|
||||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
|
||||||
<array key="orderedObjects">
|
|
||||||
<object class="IBObjectRecord">
|
|
||||||
<int key="objectID">0</int>
|
|
||||||
<array key="object" id="0"/>
|
|
||||||
<reference key="children" ref="1000"/>
|
|
||||||
<nil key="parent"/>
|
|
||||||
</object>
|
|
||||||
<object class="IBObjectRecord">
|
|
||||||
<int key="objectID">-1</int>
|
|
||||||
<reference key="object" ref="841351856"/>
|
|
||||||
<reference key="parent" ref="0"/>
|
|
||||||
<string key="objectName">File's Owner</string>
|
|
||||||
</object>
|
|
||||||
<object class="IBObjectRecord">
|
|
||||||
<int key="objectID">-2</int>
|
|
||||||
<reference key="object" ref="371349661"/>
|
|
||||||
<reference key="parent" ref="0"/>
|
|
||||||
</object>
|
|
||||||
<object class="IBObjectRecord">
|
|
||||||
<int key="objectID">2</int>
|
|
||||||
<reference key="object" ref="709618507"/>
|
|
||||||
<reference key="parent" ref="0"/>
|
|
||||||
</object>
|
|
||||||
</array>
|
|
||||||
</object>
|
|
||||||
<dictionary class="NSMutableDictionary" key="flattenedProperties">
|
|
||||||
<string key="-1.CustomClassName">MasterViewController</string>
|
|
||||||
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
|
||||||
<string key="-2.CustomClassName">UIResponder</string>
|
|
||||||
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
|
||||||
<string key="2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
|
||||||
</dictionary>
|
|
||||||
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
|
|
||||||
<nil key="activeLocalization"/>
|
|
||||||
<dictionary class="NSMutableDictionary" key="localizations"/>
|
|
||||||
<nil key="sourceID"/>
|
|
||||||
<int key="maxID">5</int>
|
|
||||||
</object>
|
|
||||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
|
||||||
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
|
|
||||||
<object class="IBPartialClassDescription">
|
|
||||||
<string key="className">MasterViewController</string>
|
|
||||||
<string key="superclassName">UITableViewController</string>
|
|
||||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
|
||||||
<string key="majorKey">IBProjectSource</string>
|
|
||||||
<string key="minorKey">./Classes/MasterViewController.h</string>
|
|
||||||
</object>
|
|
||||||
</object>
|
|
||||||
</array>
|
|
||||||
</object>
|
|
||||||
<int key="IBDocument.localizationMode">0</int>
|
|
||||||
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
|
|
||||||
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
|
|
||||||
<int key="IBDocument.defaultPropertyAccessControl">3</int>
|
|
||||||
<string key="IBCocoaTouchPluginVersion">916</string>
|
|
||||||
</data>
|
|
||||||
</archive>
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
//
|
/*
|
||||||
// main.m
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage Demo
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Olivier Poitrey on 09/05/12.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
// Copyright (c) 2012 Dailymotion. All rights reserved.
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
|
|
||||||
284
README.md
284
README.md
|
|
@ -1,5 +1,5 @@
|
||||||
Web Image
|
SDWebImage
|
||||||
=========
|
==========
|
||||||
[](https://travis-ci.org/rs/SDWebImage)
|
[](https://travis-ci.org/rs/SDWebImage)
|
||||||
[](http://cocoadocs.org/docsets/SDWebImage/)
|
[](http://cocoadocs.org/docsets/SDWebImage/)
|
||||||
[](http://cocoadocs.org/docsets/SDWebImage/)
|
[](http://cocoadocs.org/docsets/SDWebImage/)
|
||||||
|
|
@ -8,178 +8,80 @@ Web Image
|
||||||
[](https://www.versioneye.com/objective-c/sdwebimage/references)
|
[](https://www.versioneye.com/objective-c/sdwebimage/references)
|
||||||
[](https://github.com/rs/SDWebImage)
|
[](https://github.com/rs/SDWebImage)
|
||||||
|
|
||||||
This library provides a category for UIImageView with support for remote images coming from the web.
|
This library provides an async image downloader with cache support. For convenience, we added categories for some `UIControl` elements like `UIImageView`.
|
||||||
|
|
||||||
It provides:
|
## Features
|
||||||
|
|
||||||
- An `UIImageView` category adding web image and cache management to the Cocoa Touch framework
|
- [x] Categories for `UIImageView`, `UIButton`, `MKAnnotationView` adding web image and cache management
|
||||||
- An asynchronous image downloader
|
- [x] An asynchronous image downloader
|
||||||
- An asynchronous memory + disk image caching with automatic cache expiration handling
|
- [x] An asynchronous memory + disk image caching with automatic cache expiration handling
|
||||||
- Animated GIF support
|
- [x] A background image decompression
|
||||||
- WebP format support
|
- [x] A guarantee that the same URL won't be downloaded several times
|
||||||
- A background image decompression
|
- [x] A guarantee that bogus URLs won't be retried again and again
|
||||||
- A guarantee that the same URL won't be downloaded several times
|
- [x] A guarantee that main thread will never be blocked
|
||||||
- A guarantee that bogus URLs won't be retried again and again
|
- [x] Performances!
|
||||||
- A guarantee that main thread will never be blocked
|
- [x] Use GCD and ARC
|
||||||
- Performances!
|
|
||||||
- Use GCD and ARC
|
|
||||||
- Arm64 support
|
|
||||||
|
|
||||||
NOTE: Version 3.8 of SDWebImage requires iOS 7 or later (because of NSURLSession).
|
## Supported Image Formats
|
||||||
Versions 3.7 to 3.0 requires iOS 5.1.1. If you need iOS < 5.0 support, please use the last [2.0 version](https://github.com/rs/SDWebImage/tree/2.0-compat).
|
|
||||||
|
|
||||||
[How is SDWebImage better than X?](https://github.com/rs/SDWebImage/wiki/How-is-SDWebImage-better-than-X%3F)
|
- Image formats supported by UIImage (JPEG, PNG, ...), including GIF
|
||||||
|
- WebP format (use the `WebP` subspec)
|
||||||
|
|
||||||
Who Uses It
|
## Requirements
|
||||||
----------
|
|
||||||
|
|
||||||
Find out [who uses SDWebImage](https://github.com/rs/SDWebImage/wiki/Who-Uses-SDWebImage) and add your app to the list.
|
- iOS 5.1.1+ / tvOS 9.0+
|
||||||
|
- Xcode 7.1+
|
||||||
|
|
||||||
How To Use
|
#### Backwards compatibility
|
||||||
----------
|
|
||||||
|
|
||||||
API documentation is available at [CocoaDocs - SDWebImage](http://cocoadocs.org/docsets/SDWebImage/)
|
- For iOS < 5.0, please use the last [2.0 version](https://github.com/rs/SDWebImage/tree/2.0-compat).
|
||||||
|
|
||||||
### Using UIImageView+WebCache category with UITableView
|
## Getting Started
|
||||||
|
|
||||||
Just #import the UIImageView+WebCache.h header, and call the sd_setImageWithURL:placeholderImage:
|
- Read this Readme doc
|
||||||
method from the tableView:cellForRowAtIndexPath: UITableViewDataSource method. Everything will be
|
- Read the [How to use section](https://github.com/rs/SDWebImage#how-to-use)
|
||||||
handled for you, from async downloads to caching management.
|
- Read the [documentation @ CocoaDocs](http://cocoadocs.org/docsets/SDWebImage/)
|
||||||
|
- Read [How is SDWebImage better than X?](https://github.com/rs/SDWebImage/wiki/How-is-SDWebImage-better-than-X%3F)
|
||||||
|
- Try the example by downloading the project from Github or even easier using CocoaPods try `pod try SDWebImage`
|
||||||
|
- Get to the [installation steps](https://github.com/rs/SDWebImage#installation)
|
||||||
|
|
||||||
|
## Who Uses It
|
||||||
|
- Find out [who uses SDWebImage](https://github.com/rs/SDWebImage/wiki/Who-Uses-SDWebImage) and add your app to the list.
|
||||||
|
|
||||||
|
## Communication
|
||||||
|
|
||||||
|
- If you **need help**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/sdwebimage). (Tag 'sdwebimage')
|
||||||
|
- If you'd like to **ask a general question**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/sdwebimage).
|
||||||
|
- If you **found a bug**, open an issue.
|
||||||
|
- If you **have a feature request**, open an issue.
|
||||||
|
- If you **want to contribute**, submit a pull request.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
## How To Use
|
||||||
|
|
||||||
```objective-c
|
```objective-c
|
||||||
|
Objective-C:
|
||||||
|
|
||||||
#import <SDWebImage/UIImageView+WebCache.h>
|
#import <SDWebImage/UIImageView+WebCache.h>
|
||||||
|
|
||||||
...
|
...
|
||||||
|
[imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
|
||||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
|
||||||
static NSString *MyIdentifier = @"MyIdentifier";
|
|
||||||
|
|
||||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
|
|
||||||
if (cell == nil) {
|
|
||||||
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
|
|
||||||
reuseIdentifier:MyIdentifier] autorelease];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Here we use the new provided sd_setImageWithURL: method to load the web image
|
|
||||||
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
|
|
||||||
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
|
|
||||||
|
|
||||||
cell.textLabel.text = @"My Text";
|
|
||||||
return cell;
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Using blocks
|
```swift
|
||||||
|
Swift:
|
||||||
|
|
||||||
With blocks, you can be notified about the image download progress and whenever the image retrieval
|
imageView.sd_setImageWithURL(NSURL(string: "http://www.domain.com/path/to/image.jpg"), placeholderImage:UIImage(imageNamed:"placeholder.png"))
|
||||||
has completed with success or not:
|
|
||||||
|
|
||||||
```objective-c
|
|
||||||
// Here we use the new provided sd_setImageWithURL: method to load the web image
|
|
||||||
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
|
|
||||||
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
|
|
||||||
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
... completion code here ...
|
|
||||||
}];
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Note: neither your success nor failure block will be call if your image request is canceled before completion.
|
- For details about how to use the library and clear examples, see [The detailed How to use](https://raw.github.com/rs/SDWebImage/master/Docs/HowToUse.md)
|
||||||
|
|
||||||
### Using SDWebImageManager
|
## Animated Images (GIF) support
|
||||||
|
|
||||||
The SDWebImageManager is the class behind the UIImageView+WebCache category. It ties the
|
|
||||||
asynchronous downloader with the image cache store. You can use this class directly to benefit
|
|
||||||
from web image downloading with caching in another context than a UIView (ie: with Cocoa).
|
|
||||||
|
|
||||||
Here is a simple example of how to use SDWebImageManager:
|
|
||||||
|
|
||||||
```objective-c
|
|
||||||
SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
|
||||||
[manager downloadImageWithURL:imageURL
|
|
||||||
options:0
|
|
||||||
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
|
||||||
// progression tracking code
|
|
||||||
}
|
|
||||||
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
|
||||||
if (image) {
|
|
||||||
// do something with image
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
```
|
|
||||||
|
|
||||||
### Using Asynchronous Image Downloader Independently
|
|
||||||
|
|
||||||
It's also possible to use the async image downloader independently:
|
|
||||||
|
|
||||||
```objective-c
|
|
||||||
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
|
|
||||||
[downloader downloadImageWithURL:imageURL
|
|
||||||
options:0
|
|
||||||
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
|
||||||
// progression tracking code
|
|
||||||
}
|
|
||||||
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
|
||||||
if (image && finished) {
|
|
||||||
// do something with image
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
```
|
|
||||||
|
|
||||||
### Using Asynchronous Image Caching Independently
|
|
||||||
|
|
||||||
It is also possible to use the async based image cache store independently. SDImageCache
|
|
||||||
maintains a memory cache and an optional disk cache. Disk cache write operations are performed
|
|
||||||
asynchronous so it doesn't add unnecessary latency to the UI.
|
|
||||||
|
|
||||||
The SDImageCache class provides a singleton instance for convenience but you can create your own
|
|
||||||
instance if you want to create separated cache namespace.
|
|
||||||
|
|
||||||
To lookup the cache, you use the `queryDiskCacheForKey:done:` method. If the method returns nil, it means the cache
|
|
||||||
doesn't currently own the image. You are thus responsible for generating and caching it. The cache
|
|
||||||
key is an application unique identifier for the image to cache. It is generally the absolute URL of
|
|
||||||
the image.
|
|
||||||
|
|
||||||
```objective-c
|
|
||||||
SDImageCache *imageCache = [[SDImageCache alloc] initWithNamespace:@"myNamespace"];
|
|
||||||
[imageCache queryDiskCacheForKey:myCacheKey done:^(UIImage *image) {
|
|
||||||
// image is not nil if image was found
|
|
||||||
}];
|
|
||||||
```
|
|
||||||
|
|
||||||
By default SDImageCache will lookup the disk cache if an image can't be found in the memory cache.
|
|
||||||
You can prevent this from happening by calling the alternative method `imageFromMemoryCacheForKey:`.
|
|
||||||
|
|
||||||
To store an image into the cache, you use the storeImage:forKey: method:
|
|
||||||
|
|
||||||
```objective-c
|
|
||||||
[[SDImageCache sharedImageCache] storeImage:myImage forKey:myCacheKey];
|
|
||||||
```
|
|
||||||
|
|
||||||
By default, the image will be stored in memory cache as well as on disk cache (asynchronously). If
|
|
||||||
you want only the memory cache, use the alternative method storeImage:forKey:toDisk: with a negative
|
|
||||||
third argument.
|
|
||||||
|
|
||||||
### Using cache key filter
|
|
||||||
|
|
||||||
Sometime, you may not want to use the image URL as cache key because part of the URL is dynamic
|
|
||||||
(i.e.: for access control purpose). SDWebImageManager provides a way to set a cache key filter that
|
|
||||||
takes the NSURL as input, and output a cache key NSString.
|
|
||||||
|
|
||||||
The following example sets a filter in the application delegate that will remove any query-string from
|
|
||||||
the URL before to use it as a cache key:
|
|
||||||
|
|
||||||
```objective-c
|
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
|
||||||
SDWebImageManager.sharedManager.cacheKeyFilter = ^(NSURL *url) {
|
|
||||||
url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path];
|
|
||||||
return [url absoluteString];
|
|
||||||
};
|
|
||||||
|
|
||||||
// Your app init code...
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
- Starting with the 4.0 version, we relly on [FLAnimatedImage](https://github.com/Flipboard/FLAnimatedImage) to take care of our animated images.
|
||||||
|
- To use it, simply make sure you us `FLAnimatedImageView` instead of `UIImageView`.
|
||||||
|
- Note: there is a backwards compatible feature, so if you are still trying to load a GIF into a `UIImageView`, it will only show the 1st frame as a static image.
|
||||||
|
|
||||||
Common Problems
|
Common Problems
|
||||||
---------------
|
---------------
|
||||||
|
|
@ -201,8 +103,8 @@ If you don't control the image server you're using, you may not be able to chang
|
||||||
|
|
||||||
``` objective-c
|
``` objective-c
|
||||||
[imageView sd_setImageWithURL:[NSURL URLWithString:@"https://graph.facebook.com/olivier.poitrey/picture"]
|
[imageView sd_setImageWithURL:[NSURL URLWithString:@"https://graph.facebook.com/olivier.poitrey/picture"]
|
||||||
placeholderImage:[UIImage imageNamed:@"avatar-placeholder.png"]
|
placeholderImage:[UIImage imageNamed:@"avatar-placeholder.png"]
|
||||||
options:SDWebImageRefreshCached];
|
options:SDWebImageRefreshCached];
|
||||||
```
|
```
|
||||||
|
|
||||||
### Add a progress indicator
|
### Add a progress indicator
|
||||||
|
|
@ -214,8 +116,8 @@ Installation
|
||||||
|
|
||||||
There are three ways to use SDWebImage in your project:
|
There are three ways to use SDWebImage in your project:
|
||||||
- using CocoaPods
|
- using CocoaPods
|
||||||
- copying all the files into your project
|
- using Carthage
|
||||||
- importing the project as a static library
|
- by cloning the project into your repository
|
||||||
|
|
||||||
### Installation with CocoaPods
|
### Installation with CocoaPods
|
||||||
|
|
||||||
|
|
@ -253,63 +155,8 @@ To install with carthage, follow the instruction on [Carthage](https://github.co
|
||||||
github "rs/SDWebImage"
|
github "rs/SDWebImage"
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Usage
|
|
||||||
Swift
|
|
||||||
|
|
||||||
If you installed using CocoaPods:
|
|
||||||
```
|
|
||||||
import SDWebImage
|
|
||||||
```
|
|
||||||
|
|
||||||
If you installed manually:
|
|
||||||
```
|
|
||||||
import WebImage
|
|
||||||
```
|
|
||||||
|
|
||||||
Objective-C
|
|
||||||
|
|
||||||
```
|
|
||||||
@import WebImage;
|
|
||||||
```
|
|
||||||
|
|
||||||
### Installation by cloning the repository
|
### Installation by cloning the repository
|
||||||
|
- see [Manual install](https://raw.github.com/rs/SDWebImage/master/Docs/ManualInstallation.md)
|
||||||
In order to gain access to all the files from the repository, you should clone it.
|
|
||||||
```
|
|
||||||
git clone --recursive https://github.com/rs/SDWebImage.git
|
|
||||||
```
|
|
||||||
|
|
||||||
### Add the SDWebImage project to your project
|
|
||||||
|
|
||||||
- Download and unzip the last version of the framework from the [download page](https://github.com/rs/SDWebImage/releases)
|
|
||||||
- Right-click on the project navigator and select "Add Files to "Your Project":
|
|
||||||
- In the dialog, select SDWebImage.framework:
|
|
||||||
- Check the "Copy items into destination group's folder (if needed)" checkbox
|
|
||||||
|
|
||||||
### Add dependencies
|
|
||||||
|
|
||||||
- In you application project app’s target settings, find the "Build Phases" section and open the "Link Binary With Libraries" block:
|
|
||||||
- Click the "+" button again and select the "ImageIO.framework", this is needed by the progressive download feature:
|
|
||||||
|
|
||||||
### Add Linker Flag
|
|
||||||
|
|
||||||
Open the "Build Settings" tab, in the "Linking" section, locate the "Other Linker Flags" setting and add the "-ObjC" flag:
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
Alternatively, if this causes compilation problems with frameworks that extend optional libraries, such as Parse, RestKit or opencv2, instead of the -ObjC flag use:
|
|
||||||
```
|
|
||||||
-force_load SDWebImage.framework/Versions/Current/SDWebImage
|
|
||||||
```
|
|
||||||
|
|
||||||
If you're using Cocoa Pods and have any frameworks that extend optional libraries, such as Parsen RestKit or opencv2, instead of the -ObjC flag use:
|
|
||||||
```
|
|
||||||
-force_load $(TARGET_BUILD_DIR)/libPods.a
|
|
||||||
```
|
|
||||||
and this:
|
|
||||||
```
|
|
||||||
$(inherited)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Import headers in your source files
|
### Import headers in your source files
|
||||||
|
|
||||||
|
|
@ -332,3 +179,14 @@ Future Enhancements
|
||||||
## Licenses
|
## Licenses
|
||||||
|
|
||||||
All source code is licensed under the [MIT License](https://raw.github.com/rs/SDWebImage/master/LICENSE).
|
All source code is licensed under the [MIT License](https://raw.github.com/rs/SDWebImage/master/LICENSE).
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
<p align="center" >
|
||||||
|
<img src="Docs/SDWebImageClassDiagram.png" title="SDWebImage class diagram">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center" >
|
||||||
|
<img src="Docs/SDWebImageSequenceDiagram.png" title="SDWebImage sequence diagram">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,16 @@ Pod::Spec.new do |s|
|
||||||
mk.dependency 'SDWebImage/Core'
|
mk.dependency 'SDWebImage/Core'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
s.subspec 'GIF' do |gif|
|
||||||
|
gif.ios.deployment_target = '6.0'
|
||||||
|
gif.source_files = 'SDWebImage/FLAnimatedImage/*.{h,m}'
|
||||||
|
gif.dependency 'SDWebImage/Core'
|
||||||
|
gif.dependency 'FLAnimatedImage', '~> 1.0'
|
||||||
|
gif.xcconfig = {
|
||||||
|
'USER_HEADER_SEARCH_PATHS' => '$(inherited) $(SRCROOT)/FLAnimatedImage/FLAnimatedImage'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
s.subspec 'WebP' do |webp|
|
s.subspec 'WebP' do |webp|
|
||||||
webp.source_files = 'SDWebImage/UIImage+WebP.{h,m}'
|
webp.source_files = 'SDWebImage/UIImage+WebP.{h,m}'
|
||||||
webp.xcconfig = {
|
webp.xcconfig = {
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "0710"
|
LastUpgradeVersion = "0730"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
|
@ -15,8 +15,8 @@
|
||||||
<BuildableReference
|
<BuildableReference
|
||||||
BuildableIdentifier = "primary"
|
BuildableIdentifier = "primary"
|
||||||
BlueprintIdentifier = "4A2CADFE1AB4BB5300B6BC39"
|
BlueprintIdentifier = "4A2CADFE1AB4BB5300B6BC39"
|
||||||
BuildableName = "WebImage.framework"
|
BuildableName = "SDWebImage.framework"
|
||||||
BlueprintName = "WebImage"
|
BlueprintName = "SDWebImage iOS"
|
||||||
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
</BuildableReference>
|
</BuildableReference>
|
||||||
</BuildActionEntry>
|
</BuildActionEntry>
|
||||||
|
|
@ -46,8 +46,8 @@
|
||||||
<BuildableReference
|
<BuildableReference
|
||||||
BuildableIdentifier = "primary"
|
BuildableIdentifier = "primary"
|
||||||
BlueprintIdentifier = "4A2CADFE1AB4BB5300B6BC39"
|
BlueprintIdentifier = "4A2CADFE1AB4BB5300B6BC39"
|
||||||
BuildableName = "WebImage.framework"
|
BuildableName = "SDWebImage.framework"
|
||||||
BlueprintName = "WebImage"
|
BlueprintName = "SDWebImage iOS"
|
||||||
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
</BuildableReference>
|
</BuildableReference>
|
||||||
</MacroExpansion>
|
</MacroExpansion>
|
||||||
|
|
@ -64,8 +64,8 @@
|
||||||
<BuildableReference
|
<BuildableReference
|
||||||
BuildableIdentifier = "primary"
|
BuildableIdentifier = "primary"
|
||||||
BlueprintIdentifier = "4A2CADFE1AB4BB5300B6BC39"
|
BlueprintIdentifier = "4A2CADFE1AB4BB5300B6BC39"
|
||||||
BuildableName = "WebImage.framework"
|
BuildableName = "SDWebImage.framework"
|
||||||
BlueprintName = "WebImage"
|
BlueprintName = "SDWebImage iOS"
|
||||||
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
</BuildableReference>
|
</BuildableReference>
|
||||||
</MacroExpansion>
|
</MacroExpansion>
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "0710"
|
LastUpgradeVersion = "0730"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
|
@ -15,8 +15,8 @@
|
||||||
<BuildableReference
|
<BuildableReference
|
||||||
BuildableIdentifier = "primary"
|
BuildableIdentifier = "primary"
|
||||||
BlueprintIdentifier = "00733A4B1BC487C000A5A117"
|
BlueprintIdentifier = "00733A4B1BC487C000A5A117"
|
||||||
BuildableName = "WebImage.framework"
|
BuildableName = "SDWebImage.framework"
|
||||||
BlueprintName = "WebImage tvOS"
|
BlueprintName = "SDWebImage tvOS"
|
||||||
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
</BuildableReference>
|
</BuildableReference>
|
||||||
</BuildActionEntry>
|
</BuildActionEntry>
|
||||||
|
|
@ -46,8 +46,8 @@
|
||||||
<BuildableReference
|
<BuildableReference
|
||||||
BuildableIdentifier = "primary"
|
BuildableIdentifier = "primary"
|
||||||
BlueprintIdentifier = "00733A4B1BC487C000A5A117"
|
BlueprintIdentifier = "00733A4B1BC487C000A5A117"
|
||||||
BuildableName = "WebImage.framework"
|
BuildableName = "SDWebImage.framework"
|
||||||
BlueprintName = "WebImage tvOS"
|
BlueprintName = "SDWebImage tvOS"
|
||||||
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
</BuildableReference>
|
</BuildableReference>
|
||||||
</MacroExpansion>
|
</MacroExpansion>
|
||||||
|
|
@ -64,8 +64,8 @@
|
||||||
<BuildableReference
|
<BuildableReference
|
||||||
BuildableIdentifier = "primary"
|
BuildableIdentifier = "primary"
|
||||||
BlueprintIdentifier = "00733A4B1BC487C000A5A117"
|
BlueprintIdentifier = "00733A4B1BC487C000A5A117"
|
||||||
BuildableName = "WebImage.framework"
|
BuildableName = "SDWebImage.framework"
|
||||||
BlueprintName = "WebImage tvOS"
|
BlueprintName = "SDWebImage tvOS"
|
||||||
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
||||||
</BuildableReference>
|
</BuildableReference>
|
||||||
</MacroExpansion>
|
</MacroExpansion>
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "0710"
|
LastUpgradeVersion = "0730"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "0710"
|
LastUpgradeVersion = "0730"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<Scheme
|
|
||||||
LastUpgradeVersion = "0710"
|
|
||||||
version = "1.3">
|
|
||||||
<BuildAction
|
|
||||||
parallelizeBuildables = "YES"
|
|
||||||
buildImplicitDependencies = "YES">
|
|
||||||
<BuildActionEntries>
|
|
||||||
<BuildActionEntry
|
|
||||||
buildForTesting = "YES"
|
|
||||||
buildForRunning = "YES"
|
|
||||||
buildForProfiling = "YES"
|
|
||||||
buildForArchiving = "YES"
|
|
||||||
buildForAnalyzing = "YES">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "531041C2157EAFA400BBABC3"
|
|
||||||
BuildableName = "libSDWebImage+MKAnnotation.a"
|
|
||||||
BlueprintName = "SDWebImage+MKAnnotation"
|
|
||||||
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildActionEntry>
|
|
||||||
</BuildActionEntries>
|
|
||||||
</BuildAction>
|
|
||||||
<TestAction
|
|
||||||
buildConfiguration = "Debug"
|
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
|
||||||
<Testables>
|
|
||||||
</Testables>
|
|
||||||
<AdditionalOptions>
|
|
||||||
</AdditionalOptions>
|
|
||||||
</TestAction>
|
|
||||||
<LaunchAction
|
|
||||||
buildConfiguration = "Debug"
|
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
||||||
launchStyle = "0"
|
|
||||||
useCustomWorkingDirectory = "NO"
|
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
|
||||||
debugDocumentVersioning = "YES"
|
|
||||||
debugServiceExtension = "internal"
|
|
||||||
allowLocationSimulation = "YES">
|
|
||||||
<MacroExpansion>
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "531041C2157EAFA400BBABC3"
|
|
||||||
BuildableName = "libSDWebImage+MKAnnotation.a"
|
|
||||||
BlueprintName = "SDWebImage+MKAnnotation"
|
|
||||||
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</MacroExpansion>
|
|
||||||
<AdditionalOptions>
|
|
||||||
</AdditionalOptions>
|
|
||||||
</LaunchAction>
|
|
||||||
<ProfileAction
|
|
||||||
buildConfiguration = "Release"
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
|
||||||
savedToolIdentifier = ""
|
|
||||||
useCustomWorkingDirectory = "NO"
|
|
||||||
debugDocumentVersioning = "YES">
|
|
||||||
</ProfileAction>
|
|
||||||
<AnalyzeAction
|
|
||||||
buildConfiguration = "Debug">
|
|
||||||
</AnalyzeAction>
|
|
||||||
<ArchiveAction
|
|
||||||
buildConfiguration = "Release"
|
|
||||||
revealArchiveInOrganizer = "YES">
|
|
||||||
</ArchiveAction>
|
|
||||||
</Scheme>
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<Scheme
|
|
||||||
LastUpgradeVersion = "0710"
|
|
||||||
version = "1.3">
|
|
||||||
<BuildAction
|
|
||||||
parallelizeBuildables = "YES"
|
|
||||||
buildImplicitDependencies = "YES">
|
|
||||||
<BuildActionEntries>
|
|
||||||
<BuildActionEntry
|
|
||||||
buildForTesting = "YES"
|
|
||||||
buildForRunning = "YES"
|
|
||||||
buildForProfiling = "YES"
|
|
||||||
buildForArchiving = "YES"
|
|
||||||
buildForAnalyzing = "YES">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "539F912B16316D2D00160719"
|
|
||||||
BuildableName = "SDWebImageFramework"
|
|
||||||
BlueprintName = "SDWebImageFramework"
|
|
||||||
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildActionEntry>
|
|
||||||
</BuildActionEntries>
|
|
||||||
</BuildAction>
|
|
||||||
<TestAction
|
|
||||||
buildConfiguration = "Debug"
|
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
|
||||||
<Testables>
|
|
||||||
</Testables>
|
|
||||||
<AdditionalOptions>
|
|
||||||
</AdditionalOptions>
|
|
||||||
</TestAction>
|
|
||||||
<LaunchAction
|
|
||||||
buildConfiguration = "Debug"
|
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
||||||
launchStyle = "0"
|
|
||||||
useCustomWorkingDirectory = "NO"
|
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
|
||||||
debugDocumentVersioning = "YES"
|
|
||||||
debugServiceExtension = "internal"
|
|
||||||
allowLocationSimulation = "YES">
|
|
||||||
<MacroExpansion>
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "539F912B16316D2D00160719"
|
|
||||||
BuildableName = "SDWebImageFramework"
|
|
||||||
BlueprintName = "SDWebImageFramework"
|
|
||||||
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</MacroExpansion>
|
|
||||||
<AdditionalOptions>
|
|
||||||
</AdditionalOptions>
|
|
||||||
</LaunchAction>
|
|
||||||
<ProfileAction
|
|
||||||
buildConfiguration = "Release"
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
|
||||||
savedToolIdentifier = ""
|
|
||||||
useCustomWorkingDirectory = "NO"
|
|
||||||
debugDocumentVersioning = "YES">
|
|
||||||
</ProfileAction>
|
|
||||||
<AnalyzeAction
|
|
||||||
buildConfiguration = "Debug">
|
|
||||||
</AnalyzeAction>
|
|
||||||
<ArchiveAction
|
|
||||||
buildConfiguration = "Release"
|
|
||||||
revealArchiveInOrganizer = "YES">
|
|
||||||
</ArchiveAction>
|
|
||||||
</Scheme>
|
|
||||||
|
|
@ -1,99 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<Scheme
|
|
||||||
LastUpgradeVersion = "0710"
|
|
||||||
version = "1.3">
|
|
||||||
<BuildAction
|
|
||||||
parallelizeBuildables = "YES"
|
|
||||||
buildImplicitDependencies = "YES">
|
|
||||||
<BuildActionEntries>
|
|
||||||
<BuildActionEntry
|
|
||||||
buildForTesting = "YES"
|
|
||||||
buildForRunning = "YES"
|
|
||||||
buildForProfiling = "NO"
|
|
||||||
buildForArchiving = "NO"
|
|
||||||
buildForAnalyzing = "YES">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "DA248D52195472AA00390AB0"
|
|
||||||
BuildableName = "Tests.xctest"
|
|
||||||
BlueprintName = "Tests"
|
|
||||||
ReferencedContainer = "container:Tests/SDWebImage Tests.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildActionEntry>
|
|
||||||
</BuildActionEntries>
|
|
||||||
</BuildAction>
|
|
||||||
<TestAction
|
|
||||||
buildConfiguration = "Debug"
|
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
|
||||||
<Testables>
|
|
||||||
<TestableReference
|
|
||||||
skipped = "NO">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "DA248D52195472AA00390AB0"
|
|
||||||
BuildableName = "Tests.xctest"
|
|
||||||
BlueprintName = "Tests"
|
|
||||||
ReferencedContainer = "container:Tests/SDWebImage Tests.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</TestableReference>
|
|
||||||
</Testables>
|
|
||||||
<MacroExpansion>
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "DA248D52195472AA00390AB0"
|
|
||||||
BuildableName = "Tests.xctest"
|
|
||||||
BlueprintName = "Tests"
|
|
||||||
ReferencedContainer = "container:Tests/SDWebImage Tests.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</MacroExpansion>
|
|
||||||
<AdditionalOptions>
|
|
||||||
</AdditionalOptions>
|
|
||||||
</TestAction>
|
|
||||||
<LaunchAction
|
|
||||||
buildConfiguration = "Debug"
|
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
||||||
launchStyle = "0"
|
|
||||||
useCustomWorkingDirectory = "NO"
|
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
|
||||||
debugDocumentVersioning = "YES"
|
|
||||||
debugServiceExtension = "internal"
|
|
||||||
allowLocationSimulation = "YES">
|
|
||||||
<MacroExpansion>
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "DA248D52195472AA00390AB0"
|
|
||||||
BuildableName = "Tests.xctest"
|
|
||||||
BlueprintName = "Tests"
|
|
||||||
ReferencedContainer = "container:Tests/SDWebImage Tests.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</MacroExpansion>
|
|
||||||
<AdditionalOptions>
|
|
||||||
</AdditionalOptions>
|
|
||||||
</LaunchAction>
|
|
||||||
<ProfileAction
|
|
||||||
buildConfiguration = "Release"
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
|
||||||
savedToolIdentifier = ""
|
|
||||||
useCustomWorkingDirectory = "NO"
|
|
||||||
debugDocumentVersioning = "YES">
|
|
||||||
<MacroExpansion>
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "DA248D52195472AA00390AB0"
|
|
||||||
BuildableName = "Tests.xctest"
|
|
||||||
BlueprintName = "Tests"
|
|
||||||
ReferencedContainer = "container:Tests/SDWebImage Tests.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</MacroExpansion>
|
|
||||||
</ProfileAction>
|
|
||||||
<AnalyzeAction
|
|
||||||
buildConfiguration = "Debug">
|
|
||||||
</AnalyzeAction>
|
|
||||||
<ArchiveAction
|
|
||||||
buildConfiguration = "Release"
|
|
||||||
revealArchiveInOrganizer = "YES">
|
|
||||||
</ArchiveAction>
|
|
||||||
</Scheme>
|
|
||||||
|
|
@ -1,80 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<Scheme
|
|
||||||
LastUpgradeVersion = "0710"
|
|
||||||
version = "1.3">
|
|
||||||
<BuildAction
|
|
||||||
parallelizeBuildables = "YES"
|
|
||||||
buildImplicitDependencies = "YES">
|
|
||||||
<BuildActionEntries>
|
|
||||||
<BuildActionEntry
|
|
||||||
buildForTesting = "YES"
|
|
||||||
buildForRunning = "YES"
|
|
||||||
buildForProfiling = "YES"
|
|
||||||
buildForArchiving = "YES"
|
|
||||||
buildForAnalyzing = "YES">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "4A2CADFE1AB4BB5300B6BC39"
|
|
||||||
BuildableName = "WebImage.framework"
|
|
||||||
BlueprintName = "WebImage"
|
|
||||||
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildActionEntry>
|
|
||||||
</BuildActionEntries>
|
|
||||||
</BuildAction>
|
|
||||||
<TestAction
|
|
||||||
buildConfiguration = "Debug"
|
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
|
||||||
<Testables>
|
|
||||||
</Testables>
|
|
||||||
<AdditionalOptions>
|
|
||||||
</AdditionalOptions>
|
|
||||||
</TestAction>
|
|
||||||
<LaunchAction
|
|
||||||
buildConfiguration = "Debug"
|
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
||||||
launchStyle = "0"
|
|
||||||
useCustomWorkingDirectory = "NO"
|
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
|
||||||
debugDocumentVersioning = "YES"
|
|
||||||
debugServiceExtension = "internal"
|
|
||||||
allowLocationSimulation = "YES">
|
|
||||||
<MacroExpansion>
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "4A2CADFE1AB4BB5300B6BC39"
|
|
||||||
BuildableName = "WebImage.framework"
|
|
||||||
BlueprintName = "WebImage"
|
|
||||||
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</MacroExpansion>
|
|
||||||
<AdditionalOptions>
|
|
||||||
</AdditionalOptions>
|
|
||||||
</LaunchAction>
|
|
||||||
<ProfileAction
|
|
||||||
buildConfiguration = "Release"
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
|
||||||
savedToolIdentifier = ""
|
|
||||||
useCustomWorkingDirectory = "NO"
|
|
||||||
debugDocumentVersioning = "YES">
|
|
||||||
<MacroExpansion>
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "4A2CADFE1AB4BB5300B6BC39"
|
|
||||||
BuildableName = "WebImage.framework"
|
|
||||||
BlueprintName = "WebImage"
|
|
||||||
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</MacroExpansion>
|
|
||||||
</ProfileAction>
|
|
||||||
<AnalyzeAction
|
|
||||||
buildConfiguration = "Debug">
|
|
||||||
</AnalyzeAction>
|
|
||||||
<ArchiveAction
|
|
||||||
buildConfiguration = "Release"
|
|
||||||
revealArchiveInOrganizer = "YES">
|
|
||||||
</ArchiveAction>
|
|
||||||
</Scheme>
|
|
||||||
|
|
@ -0,0 +1,141 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the SDWebImage package.
|
||||||
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#if COCOAPODS
|
||||||
|
@import FLAnimatedImage;
|
||||||
|
#else
|
||||||
|
#import "FLAnimatedImageView.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#import "SDWebImageManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A category for the FLAnimatedImage imageView class that hooks it to the SDWebImage system.
|
||||||
|
* Very similar to the base class category (UIImageView (WebCache))
|
||||||
|
*/
|
||||||
|
@interface FLAnimatedImageView (WebCache)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current image URL.
|
||||||
|
*
|
||||||
|
* Note that because of the limitations of categories this property can get out of sync
|
||||||
|
* if you use setImage: directly.
|
||||||
|
*/
|
||||||
|
- (nullable NSURL *)sd_imageURL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images
|
||||||
|
* The download is asynchronous and cached.
|
||||||
|
*
|
||||||
|
* @param url The url for the image.
|
||||||
|
*/
|
||||||
|
- (void)sd_setImageWithURL:(nullable NSURL *)url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images
|
||||||
|
* The download is asynchronous and cached.
|
||||||
|
* Uses a placeholder until the request finishes.
|
||||||
|
*
|
||||||
|
* @param url The url for the image.
|
||||||
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
|
*/
|
||||||
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images
|
||||||
|
* The download is asynchronous and cached.
|
||||||
|
* Uses a placeholder until the request finishes.
|
||||||
|
*
|
||||||
|
* @param url The url for the image.
|
||||||
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
|
*/
|
||||||
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images
|
||||||
|
* The download is asynchronous and cached.
|
||||||
|
*
|
||||||
|
* @param url The url for the image.
|
||||||
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
|
*/
|
||||||
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images
|
||||||
|
* The download is asynchronous and cached.
|
||||||
|
* Uses a placeholder until the request finishes.
|
||||||
|
*
|
||||||
|
* @param url The url for the image.
|
||||||
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
|
*/
|
||||||
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images
|
||||||
|
* The download is asynchronous and cached.
|
||||||
|
* Uses a placeholder until the request finishes.
|
||||||
|
*
|
||||||
|
* @param url The url for the image.
|
||||||
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
|
*/
|
||||||
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the image at the given url (either from cache or download) and load it in this imageView. It works with both static and dynamic images
|
||||||
|
* The download is asynchronous and cached.
|
||||||
|
* Uses a placeholder until the request finishes.
|
||||||
|
*
|
||||||
|
* @param url The url for the image.
|
||||||
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
|
* @param progressBlock A block called while image is downloading
|
||||||
|
* @param completedBlock A block called when operation has been completed. This block has no return value
|
||||||
|
* and takes the requested UIImage as first parameter. In case of error the image parameter
|
||||||
|
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
|
||||||
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
|
* The fourth parameter is the original image url.
|
||||||
|
*/
|
||||||
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel the image load
|
||||||
|
*/
|
||||||
|
- (void)sd_cancelCurrentImageLoad;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
@ -0,0 +1,119 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the SDWebImage package.
|
||||||
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#import "FLAnimatedImageView+WebCache.h"
|
||||||
|
#import "objc/runtime.h"
|
||||||
|
#import "UIView+WebCacheOperation.h"
|
||||||
|
#import "NSData+ImageContentType.h"
|
||||||
|
#import "FLAnimatedImage.h"
|
||||||
|
#import "UIImageView+WebCache.h"
|
||||||
|
|
||||||
|
static char imageURLKey;
|
||||||
|
|
||||||
|
|
||||||
|
@implementation FLAnimatedImageView (WebCache)
|
||||||
|
|
||||||
|
- (nullable NSURL *)sd_imageURL {
|
||||||
|
return objc_getAssociatedObject(self, &imageURLKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setImageWithURL:(nullable NSURL *)url {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setImageWithURL:(nullable NSURL *)url completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(SDWebImageOptions)options completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
|
[self sd_cancelCurrentImageLoad];
|
||||||
|
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
|
|
||||||
|
if (!(options & SDWebImageDelayPlaceholder)) {
|
||||||
|
dispatch_main_async_safe(^{
|
||||||
|
self.image = placeholder;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url) {
|
||||||
|
// check if activityView is enabled or not
|
||||||
|
if ([self showActivityIndicatorView]) {
|
||||||
|
[self addActivityIndicator];
|
||||||
|
}
|
||||||
|
|
||||||
|
__weak __typeof(self)wself = self;
|
||||||
|
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
|
if (!wself) return;
|
||||||
|
dispatch_main_sync_safe(^{
|
||||||
|
[wself removeActivityIndicator];
|
||||||
|
|
||||||
|
if (!wself) return;
|
||||||
|
if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) {
|
||||||
|
completedBlock(image, error, cacheType, url);
|
||||||
|
return;
|
||||||
|
} else if (image) {
|
||||||
|
NSString *imageContentType = [NSData sd_contentTypeForImageData:data];
|
||||||
|
if ([imageContentType isEqualToString:@"image/gif"]) {
|
||||||
|
wself.animatedImage = [FLAnimatedImage animatedImageWithGIFData:data];
|
||||||
|
wself.image = nil;
|
||||||
|
} else {
|
||||||
|
wself.image = image;
|
||||||
|
wself.animatedImage = nil;
|
||||||
|
}
|
||||||
|
[wself setNeedsLayout];
|
||||||
|
} else {
|
||||||
|
if ((options & SDWebImageDelayPlaceholder)) {
|
||||||
|
wself.image = placeholder;
|
||||||
|
[wself setNeedsLayout];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (completedBlock && finished) {
|
||||||
|
completedBlock(image, error, cacheType, url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}];
|
||||||
|
[self sd_setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"];
|
||||||
|
} else {
|
||||||
|
dispatch_main_async_safe(^{
|
||||||
|
[self removeActivityIndicator];
|
||||||
|
|
||||||
|
if (completedBlock) {
|
||||||
|
NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
|
||||||
|
completedBlock(nil, error, SDImageCacheTypeNone, url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sd_cancelCurrentImageLoad {
|
||||||
|
[self sd_cancelImageLoadOperationWithKey:@"UIImageViewImageLoad"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
//
|
/*
|
||||||
// MKAnnotationView+WebCache.h
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Olivier Poitrey on 14/03/12.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
// Copyright (c) 2012 Dailymotion. All rights reserved.
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#import "MapKit/MapKit.h"
|
#import "MapKit/MapKit.h"
|
||||||
#import "SDWebImageManager.h"
|
#import "SDWebImageManager.h"
|
||||||
|
|
@ -18,9 +18,9 @@
|
||||||
* Get the current image URL.
|
* Get the current image URL.
|
||||||
*
|
*
|
||||||
* Note that because of the limitations of categories this property can get out of sync
|
* Note that because of the limitations of categories this property can get out of sync
|
||||||
* if you use sd_setImage: directly.
|
* if you use setImage: directly.
|
||||||
*/
|
*/
|
||||||
- (NSURL *)sd_imageURL;
|
- (nullable NSURL *)sd_imageURL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`.
|
* Set the imageView `image` with an `url`.
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url` and a placeholder.
|
* Set the imageView `image` with an `url` and a placeholder.
|
||||||
|
|
@ -40,7 +40,8 @@
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @see sd_setImageWithURL:placeholderImage:options:
|
* @see sd_setImageWithURL:placeholderImage:options:
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||||
|
|
@ -52,7 +53,9 @@
|
||||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`.
|
* Set the imageView `image` with an `url`.
|
||||||
|
|
@ -66,7 +69,8 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder.
|
* Set the imageView `image` with an `url`, placeholder.
|
||||||
|
|
@ -81,7 +85,9 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||||
|
|
@ -97,7 +103,10 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel the current download
|
* Cancel the current download
|
||||||
|
|
@ -105,20 +114,3 @@
|
||||||
- (void)sd_cancelCurrentImageLoad;
|
- (void)sd_cancelCurrentImageLoad;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@interface MKAnnotationView (WebCacheDeprecated)
|
|
||||||
|
|
||||||
- (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`");
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`");
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`");
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:`");
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`");
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`");
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`");
|
|
||||||
|
|
||||||
- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`");
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
//
|
/*
|
||||||
// MKAnnotationView+WebCache.m
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Olivier Poitrey on 14/03/12.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
// Copyright (c) 2012 Dailymotion. All rights reserved.
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#import "MKAnnotationView+WebCache.h"
|
#import "MKAnnotationView+WebCache.h"
|
||||||
#import "objc/runtime.h"
|
#import "objc/runtime.h"
|
||||||
|
|
@ -14,31 +14,34 @@ static char imageURLKey;
|
||||||
|
|
||||||
@implementation MKAnnotationView (WebCache)
|
@implementation MKAnnotationView (WebCache)
|
||||||
|
|
||||||
- (NSURL *)sd_imageURL {
|
- (nullable NSURL *)sd_imageURL {
|
||||||
return objc_getAssociatedObject(self, &imageURLKey);
|
return objc_getAssociatedObject(self, &imageURLKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url {
|
||||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil];
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder {
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:completedBlock];
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:completedBlock];
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self sd_cancelCurrentImageLoad];
|
[self sd_cancelCurrentImageLoad];
|
||||||
|
|
||||||
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
|
|
@ -46,7 +49,7 @@ static char imageURLKey;
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
__weak __typeof(self)wself = self;
|
__weak __typeof(self)wself = self;
|
||||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
if (!wself) return;
|
if (!wself) return;
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
__strong MKAnnotationView *sself = wself;
|
__strong MKAnnotationView *sself = wself;
|
||||||
|
|
@ -84,52 +87,3 @@ static char imageURLKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation MKAnnotationView (WebCacheDeprecated)
|
|
||||||
|
|
||||||
- (NSURL *)imageURL {
|
|
||||||
return [self sd_imageURL];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url {
|
|
||||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)cancelCurrentImageLoad {
|
|
||||||
[self sd_cancelCurrentImageLoad];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
//
|
/*
|
||||||
// Created by Fabrice Aneche on 06/01/14.
|
* This file is part of the SDWebImage package.
|
||||||
// Copyright (c) 2014 Dailymotion. All rights reserved.
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
* (c) Fabrice Aneche
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
|
@ -14,13 +18,6 @@
|
||||||
*
|
*
|
||||||
* @return the content type as string (i.e. image/jpeg, image/gif)
|
* @return the content type as string (i.e. image/jpeg, image/gif)
|
||||||
*/
|
*/
|
||||||
+ (NSString *)sd_contentTypeForImageData:(NSData *)data;
|
+ (nullable NSString *)sd_contentTypeForImageData:(nullable NSData *)data;
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
|
|
||||||
@interface NSData (ImageContentTypeDeprecated)
|
|
||||||
|
|
||||||
+ (NSString *)contentTypeForImageData:(NSData *)data __deprecated_msg("Use `sd_contentTypeForImageData:`");
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,22 @@
|
||||||
//
|
/*
|
||||||
// Created by Fabrice Aneche on 06/01/14.
|
* This file is part of the SDWebImage package.
|
||||||
// Copyright (c) 2014 Dailymotion. All rights reserved.
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
* (c) Fabrice Aneche
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
#import "NSData+ImageContentType.h"
|
#import "NSData+ImageContentType.h"
|
||||||
|
|
||||||
|
|
||||||
@implementation NSData (ImageContentType)
|
@implementation NSData (ImageContentType)
|
||||||
|
|
||||||
+ (NSString *)sd_contentTypeForImageData:(NSData *)data {
|
+ (nullable NSString *)sd_contentTypeForImageData:(nullable NSData *)data {
|
||||||
|
if (!data) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t c;
|
uint8_t c;
|
||||||
[data getBytes:&c length:1];
|
[data getBytes:&c length:1];
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
|
@ -23,7 +31,7 @@
|
||||||
return @"image/tiff";
|
return @"image/tiff";
|
||||||
case 0x52:
|
case 0x52:
|
||||||
// R as RIFF for WEBP
|
// R as RIFF for WEBP
|
||||||
if ([data length] < 12) {
|
if (data.length < 12) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,12 +46,3 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation NSData (ImageContentTypeDeprecated)
|
|
||||||
|
|
||||||
+ (NSString *)contentTypeForImageData:(NSData *)data {
|
|
||||||
return [self sd_contentTypeForImageData:data];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ typedef NS_ENUM(NSInteger, SDImageCacheType) {
|
||||||
SDImageCacheTypeMemory
|
SDImageCacheTypeMemory
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType cacheType);
|
typedef void(^SDCacheQueryCompletedBlock)(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType);
|
||||||
|
|
||||||
typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache);
|
typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache);
|
||||||
|
|
||||||
|
|
@ -77,14 +77,14 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
*
|
*
|
||||||
* @return SDImageCache global instance
|
* @return SDImageCache global instance
|
||||||
*/
|
*/
|
||||||
+ (SDImageCache *)sharedImageCache;
|
+ (nonnull SDImageCache *)sharedImageCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init a new cache store with a specific namespace
|
* Init a new cache store with a specific namespace
|
||||||
*
|
*
|
||||||
* @param ns The namespace to use for this cache store
|
* @param ns The namespace to use for this cache store
|
||||||
*/
|
*/
|
||||||
- (id)initWithNamespace:(NSString *)ns;
|
- (nonnull instancetype)initWithNamespace:(nonnull NSString *)ns;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init a new cache store with a specific namespace and directory
|
* Init a new cache store with a specific namespace and directory
|
||||||
|
|
@ -92,9 +92,10 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
* @param ns The namespace to use for this cache store
|
* @param ns The namespace to use for this cache store
|
||||||
* @param directory Directory to cache disk images in
|
* @param directory Directory to cache disk images in
|
||||||
*/
|
*/
|
||||||
- (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory;
|
- (nonnull instancetype)initWithNamespace:(nonnull NSString *)ns
|
||||||
|
diskCacheDirectory:(nonnull NSString *)directory NS_DESIGNATED_INITIALIZER;
|
||||||
|
|
||||||
-(NSString *)makeDiskCachePath:(NSString*)fullNamespace;
|
- (nullable NSString *)makeDiskCachePath:(nonnull NSString*)fullNamespace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a read-only cache path to search for images pre-cached by SDImageCache
|
* Add a read-only cache path to search for images pre-cached by SDImageCache
|
||||||
|
|
@ -102,7 +103,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
*
|
*
|
||||||
* @param path The path to use for this read-only cache path
|
* @param path The path to use for this read-only cache path
|
||||||
*/
|
*/
|
||||||
- (void)addReadOnlyCachePath:(NSString *)path;
|
- (void)addReadOnlyCachePath:(nonnull NSString *)path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store an image into memory and disk cache at the given key.
|
* Store an image into memory and disk cache at the given key.
|
||||||
|
|
@ -110,7 +111,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
* @param image The image to store
|
* @param image The image to store
|
||||||
* @param key The unique image cache key, usually it's image absolute URL
|
* @param key The unique image cache key, usually it's image absolute URL
|
||||||
*/
|
*/
|
||||||
- (void)storeImage:(UIImage *)image forKey:(NSString *)key;
|
- (void)storeImage:(nullable UIImage *)image forKey:(nullable NSString *)key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store an image into memory and optionally disk cache at the given key.
|
* Store an image into memory and optionally disk cache at the given key.
|
||||||
|
|
@ -119,7 +120,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
* @param key The unique image cache key, usually it's image absolute URL
|
* @param key The unique image cache key, usually it's image absolute URL
|
||||||
* @param toDisk Store the image to disk cache if YES
|
* @param toDisk Store the image to disk cache if YES
|
||||||
*/
|
*/
|
||||||
- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk;
|
- (void)storeImage:(nullable UIImage *)image forKey:(nullable NSString *)key toDisk:(BOOL)toDisk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store an image into memory and optionally disk cache at the given key.
|
* Store an image into memory and optionally disk cache at the given key.
|
||||||
|
|
@ -132,7 +133,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
* @param key The unique image cache key, usually it's image absolute URL
|
* @param key The unique image cache key, usually it's image absolute URL
|
||||||
* @param toDisk Store the image to disk cache if YES
|
* @param toDisk Store the image to disk cache if YES
|
||||||
*/
|
*/
|
||||||
- (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk;
|
- (void)storeImage:(nullable UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(nullable NSData *)imageData forKey:(nullable NSString *)key toDisk:(BOOL)toDisk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store image NSData into disk cache at the given key.
|
* Store image NSData into disk cache at the given key.
|
||||||
|
|
@ -140,35 +141,35 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
* @param imageData The image data to store
|
* @param imageData The image data to store
|
||||||
* @param key The unique image cache key, usually it's image absolute URL
|
* @param key The unique image cache key, usually it's image absolute URL
|
||||||
*/
|
*/
|
||||||
- (void)storeImageDataToDisk:(NSData *)imageData forKey:(NSString *)key;
|
- (void)storeImageDataToDisk:(nullable NSData *)imageData forKey:(nullable NSString *)key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the disk cache asynchronously.
|
* Query the disk cache asynchronously.
|
||||||
*
|
*
|
||||||
* @param key The unique key used to store the wanted image
|
* @param key The unique key used to store the wanted image
|
||||||
*/
|
*/
|
||||||
- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock;
|
- (nullable NSOperation *)queryDiskCacheForKey:(nullable NSString *)key done:(nullable SDCacheQueryCompletedBlock)doneBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the memory cache synchronously.
|
* Query the memory cache synchronously.
|
||||||
*
|
*
|
||||||
* @param key The unique key used to store the wanted image
|
* @param key The unique key used to store the wanted image
|
||||||
*/
|
*/
|
||||||
- (UIImage *)imageFromMemoryCacheForKey:(NSString *)key;
|
- (nullable UIImage *)imageFromMemoryCacheForKey:(nullable NSString *)key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the disk cache synchronously after checking the memory cache.
|
* Query the disk cache synchronously after checking the memory cache.
|
||||||
*
|
*
|
||||||
* @param key The unique key used to store the wanted image
|
* @param key The unique key used to store the wanted image
|
||||||
*/
|
*/
|
||||||
- (UIImage *)imageFromDiskCacheForKey:(NSString *)key;
|
- (nullable UIImage *)imageFromDiskCacheForKey:(nullable NSString *)key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the image from memory and disk cache asynchronously
|
* Remove the image from memory and disk cache asynchronously
|
||||||
*
|
*
|
||||||
* @param key The unique image cache key
|
* @param key The unique image cache key
|
||||||
*/
|
*/
|
||||||
- (void)removeImageForKey:(NSString *)key;
|
- (void)removeImageForKey:(nullable NSString *)key;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -177,7 +178,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
* @param key The unique image cache key
|
* @param key The unique image cache key
|
||||||
* @param completion An block that should be executed after the image has been removed (optional)
|
* @param completion An block that should be executed after the image has been removed (optional)
|
||||||
*/
|
*/
|
||||||
- (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion;
|
- (void)removeImageForKey:(nullable NSString *)key withCompletion:(nullable SDWebImageNoParamsBlock)completion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the image from memory and optionally disk cache asynchronously
|
* Remove the image from memory and optionally disk cache asynchronously
|
||||||
|
|
@ -185,7 +186,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
* @param key The unique image cache key
|
* @param key The unique image cache key
|
||||||
* @param fromDisk Also remove cache entry from disk if YES
|
* @param fromDisk Also remove cache entry from disk if YES
|
||||||
*/
|
*/
|
||||||
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk;
|
- (void)removeImageForKey:(nullable NSString *)key fromDisk:(BOOL)fromDisk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the image from memory and optionally disk cache asynchronously
|
* Remove the image from memory and optionally disk cache asynchronously
|
||||||
|
|
@ -194,7 +195,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
* @param fromDisk Also remove cache entry from disk if YES
|
* @param fromDisk Also remove cache entry from disk if YES
|
||||||
* @param completion An block that should be executed after the image has been removed (optional)
|
* @param completion An block that should be executed after the image has been removed (optional)
|
||||||
*/
|
*/
|
||||||
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion;
|
- (void)removeImageForKey:(nullable NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(nullable SDWebImageNoParamsBlock)completion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all memory cached images
|
* Clear all memory cached images
|
||||||
|
|
@ -205,7 +206,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
* Clear all disk cached images. Non-blocking method - returns immediately.
|
* Clear all disk cached images. Non-blocking method - returns immediately.
|
||||||
* @param completion An block that should be executed after cache expiration completes (optional)
|
* @param completion An block that should be executed after cache expiration completes (optional)
|
||||||
*/
|
*/
|
||||||
- (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion;
|
- (void)clearDiskOnCompletion:(nullable SDWebImageNoParamsBlock)completion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all disk cached images
|
* Clear all disk cached images
|
||||||
|
|
@ -217,7 +218,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
* Remove all expired cached image from disk. Non-blocking method - returns immediately.
|
* Remove all expired cached image from disk. Non-blocking method - returns immediately.
|
||||||
* @param completionBlock An block that should be executed after cache expiration completes (optional)
|
* @param completionBlock An block that should be executed after cache expiration completes (optional)
|
||||||
*/
|
*/
|
||||||
- (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock;
|
- (void)cleanDiskWithCompletionBlock:(nullable SDWebImageNoParamsBlock)completionBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all expired cached image from disk
|
* Remove all expired cached image from disk
|
||||||
|
|
@ -238,7 +239,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
/**
|
/**
|
||||||
* Asynchronously calculate the disk cache's size.
|
* Asynchronously calculate the disk cache's size.
|
||||||
*/
|
*/
|
||||||
- (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock;
|
- (void)calculateSizeWithCompletionBlock:(nullable SDWebImageCalculateSizeBlock)completionBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async check if image exists in disk cache already (does not load the image)
|
* Async check if image exists in disk cache already (does not load the image)
|
||||||
|
|
@ -247,7 +248,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
* @param completionBlock the block to be executed when the check is done.
|
* @param completionBlock the block to be executed when the check is done.
|
||||||
* @note the completion block will be always executed on the main queue
|
* @note the completion block will be always executed on the main queue
|
||||||
*/
|
*/
|
||||||
- (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;
|
- (void)diskImageExistsWithKey:(nullable NSString *)key completion:(nullable SDWebImageCheckCacheCompletionBlock)completionBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if image exists in disk cache already (does not load the image)
|
* Check if image exists in disk cache already (does not load the image)
|
||||||
|
|
@ -256,7 +257,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
*
|
*
|
||||||
* @return YES if an image exists for the given key
|
* @return YES if an image exists for the given key
|
||||||
*/
|
*/
|
||||||
- (BOOL)diskImageExistsWithKey:(NSString *)key;
|
- (BOOL)diskImageExistsWithKey:(nullable NSString *)key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the cache path for a certain key (needs the cache path root folder)
|
* Get the cache path for a certain key (needs the cache path root folder)
|
||||||
|
|
@ -266,7 +267,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
*
|
*
|
||||||
* @return the cache path
|
* @return the cache path
|
||||||
*/
|
*/
|
||||||
- (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path;
|
- (nullable NSString *)cachePathForKey:(nullable NSString *)key inPath:(nonnull NSString *)path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default cache path for a certain key
|
* Get the default cache path for a certain key
|
||||||
|
|
@ -275,6 +276,6 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
*
|
*
|
||||||
* @return the default cache path
|
* @return the default cache path
|
||||||
*/
|
*/
|
||||||
- (NSString *)defaultCachePathForKey:(NSString *)key;
|
- (nullable NSString *)defaultCachePathForKey:(nullable NSString *)key;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#import "SDWebImageDecoder.h"
|
#import "SDWebImageDecoder.h"
|
||||||
#import "UIImage+MultiFormat.h"
|
#import "UIImage+MultiFormat.h"
|
||||||
#import <CommonCrypto/CommonDigest.h>
|
#import <CommonCrypto/CommonDigest.h>
|
||||||
|
#import "UIImage+GIF.h"
|
||||||
|
|
||||||
// See https://github.com/rs/SDWebImage/pull/1141 for discussion
|
// See https://github.com/rs/SDWebImage/pull/1141 for discussion
|
||||||
@interface AutoPurgeCache : NSCache
|
@interface AutoPurgeCache : NSCache
|
||||||
|
|
@ -17,8 +18,7 @@
|
||||||
|
|
||||||
@implementation AutoPurgeCache
|
@implementation AutoPurgeCache
|
||||||
|
|
||||||
- (id)init
|
- (nonnull instancetype)init {
|
||||||
{
|
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeAllObjects) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeAllObjects) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
|
||||||
|
|
@ -26,8 +26,7 @@
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc {
|
||||||
{
|
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -42,8 +41,8 @@ static NSData *kPNGSignatureData = nil;
|
||||||
BOOL ImageDataHasPNGPreffix(NSData *data);
|
BOOL ImageDataHasPNGPreffix(NSData *data);
|
||||||
|
|
||||||
BOOL ImageDataHasPNGPreffix(NSData *data) {
|
BOOL ImageDataHasPNGPreffix(NSData *data) {
|
||||||
NSUInteger pngSignatureLength = [kPNGSignatureData length];
|
NSUInteger pngSignatureLength = kPNGSignatureData.length;
|
||||||
if ([data length] >= pngSignatureLength) {
|
if (data.length >= pngSignatureLength) {
|
||||||
if ([[data subdataWithRange:NSMakeRange(0, pngSignatureLength)] isEqualToData:kPNGSignatureData]) {
|
if ([[data subdataWithRange:NSMakeRange(0, pngSignatureLength)] isEqualToData:kPNGSignatureData]) {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
@ -58,10 +57,10 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
|
|
||||||
@interface SDImageCache ()
|
@interface SDImageCache ()
|
||||||
|
|
||||||
@property (strong, nonatomic) NSCache *memCache;
|
@property (strong, nonatomic, nonnull) NSCache *memCache;
|
||||||
@property (strong, nonatomic) NSString *diskCachePath;
|
@property (strong, nonatomic, nonnull) NSString *diskCachePath;
|
||||||
@property (strong, nonatomic) NSMutableArray *customPaths;
|
@property (strong, nonatomic, nullable) NSMutableArray<NSString *> *customPaths;
|
||||||
@property (SDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t ioQueue;
|
@property (SDDispatchQueueSetterSementics, nonatomic, nullable) dispatch_queue_t ioQueue;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
@ -70,7 +69,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
NSFileManager *_fileManager;
|
NSFileManager *_fileManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (SDImageCache *)sharedImageCache {
|
+ (nonnull SDImageCache *)sharedImageCache {
|
||||||
static dispatch_once_t once;
|
static dispatch_once_t once;
|
||||||
static id instance;
|
static id instance;
|
||||||
dispatch_once(&once, ^{
|
dispatch_once(&once, ^{
|
||||||
|
|
@ -79,16 +78,17 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)init {
|
- (instancetype)init {
|
||||||
return [self initWithNamespace:@"default"];
|
return [self initWithNamespace:@"default"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithNamespace:(NSString *)ns {
|
- (nonnull instancetype)initWithNamespace:(nonnull NSString *)ns {
|
||||||
NSString *path = [self makeDiskCachePath:ns];
|
NSString *path = [self makeDiskCachePath:ns];
|
||||||
return [self initWithNamespace:ns diskCacheDirectory:path];
|
return [self initWithNamespace:ns diskCacheDirectory:path];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory {
|
- (nonnull instancetype)initWithNamespace:(nonnull NSString *)ns
|
||||||
|
diskCacheDirectory:(nonnull NSString *)directory {
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
NSString *fullNamespace = [@"com.hackemist.SDWebImageCache." stringByAppendingString:ns];
|
NSString *fullNamespace = [@"com.hackemist.SDWebImageCache." stringByAppendingString:ns];
|
||||||
|
|
||||||
|
|
@ -153,7 +153,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
SDDispatchQueueRelease(_ioQueue);
|
SDDispatchQueueRelease(_ioQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addReadOnlyCachePath:(NSString *)path {
|
- (void)addReadOnlyCachePath:(nonnull NSString *)path {
|
||||||
if (!self.customPaths) {
|
if (!self.customPaths) {
|
||||||
self.customPaths = [NSMutableArray new];
|
self.customPaths = [NSMutableArray new];
|
||||||
}
|
}
|
||||||
|
|
@ -163,19 +163,19 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path {
|
- (nullable NSString *)cachePathForKey:(nullable NSString *)key inPath:(nonnull NSString *)path {
|
||||||
NSString *filename = [self cachedFileNameForKey:key];
|
NSString *filename = [self cachedFileNameForKey:key];
|
||||||
return [path stringByAppendingPathComponent:filename];
|
return [path stringByAppendingPathComponent:filename];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)defaultCachePathForKey:(NSString *)key {
|
- (nullable NSString *)defaultCachePathForKey:(nullable NSString *)key {
|
||||||
return [self cachePathForKey:key inPath:self.diskCachePath];
|
return [self cachePathForKey:key inPath:self.diskCachePath];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark SDImageCache (private)
|
#pragma mark SDImageCache (private)
|
||||||
|
|
||||||
- (NSString *)cachedFileNameForKey:(NSString *)key {
|
- (nullable NSString *)cachedFileNameForKey:(nullable NSString *)key {
|
||||||
const char *str = [key UTF8String];
|
const char *str = key.UTF8String;
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
str = "";
|
str = "";
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +183,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
CC_MD5(str, (CC_LONG)strlen(str), r);
|
CC_MD5(str, (CC_LONG)strlen(str), r);
|
||||||
NSString *filename = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%@",
|
NSString *filename = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%@",
|
||||||
r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10],
|
r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10],
|
||||||
r[11], r[12], r[13], r[14], r[15], [[key pathExtension] isEqualToString:@""] ? @"" : [NSString stringWithFormat:@".%@", [key pathExtension]]];
|
r[11], r[12], r[13], r[14], r[15], [key.pathExtension isEqualToString:@""] ? @"" : [NSString stringWithFormat:@".%@", key.pathExtension]];
|
||||||
|
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
@ -191,12 +191,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
#pragma mark ImageCache
|
#pragma mark ImageCache
|
||||||
|
|
||||||
// Init the disk cache
|
// Init the disk cache
|
||||||
-(NSString *)makeDiskCachePath:(NSString*)fullNamespace{
|
- (nullable NSString *)makeDiskCachePath:(nonnull NSString*)fullNamespace {
|
||||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
NSArray<NSString *> *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||||
return [paths[0] stringByAppendingPathComponent:fullNamespace];
|
return [paths[0] stringByAppendingPathComponent:fullNamespace];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk {
|
- (void)storeImage:(nullable UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(nullable NSData *)imageData forKey:(nullable NSString *)key toDisk:(BOOL)toDisk {
|
||||||
if (!image || !key) {
|
if (!image || !key) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -226,7 +226,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
BOOL imageIsPng = hasAlpha;
|
BOOL imageIsPng = hasAlpha;
|
||||||
|
|
||||||
// But if we have an image data, we will look at the preffix
|
// But if we have an image data, we will look at the preffix
|
||||||
if ([imageData length] >= [kPNGSignatureData length]) {
|
if (imageData.length >= kPNGSignatureData.length) {
|
||||||
imageIsPng = ImageDataHasPNGPreffix(imageData);
|
imageIsPng = ImageDataHasPNGPreffix(imageData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -246,15 +246,15 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)storeImage:(UIImage *)image forKey:(NSString *)key {
|
- (void)storeImage:(nullable UIImage *)image forKey:(nullable NSString *)key {
|
||||||
[self storeImage:image recalculateFromImage:YES imageData:nil forKey:key toDisk:YES];
|
[self storeImage:image recalculateFromImage:YES imageData:nil forKey:key toDisk:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk {
|
- (void)storeImage:(nullable UIImage *)image forKey:(nullable NSString *)key toDisk:(BOOL)toDisk {
|
||||||
[self storeImage:image recalculateFromImage:YES imageData:nil forKey:key toDisk:toDisk];
|
[self storeImage:image recalculateFromImage:YES imageData:nil forKey:key toDisk:toDisk];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)storeImageDataToDisk:(NSData *)imageData forKey:(NSString *)key {
|
- (void)storeImageDataToDisk:(nullable NSData *)imageData forKey:(nullable NSString *)key {
|
||||||
|
|
||||||
if (!imageData) {
|
if (!imageData) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -273,11 +273,11 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
|
|
||||||
// disable iCloud backup
|
// disable iCloud backup
|
||||||
if (self.shouldDisableiCloud) {
|
if (self.shouldDisableiCloud) {
|
||||||
[fileURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
|
[fileURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)diskImageExistsWithKey:(NSString *)key {
|
- (BOOL)diskImageExistsWithKey:(nullable NSString *)key {
|
||||||
BOOL exists = NO;
|
BOOL exists = NO;
|
||||||
|
|
||||||
// this is an exception to access the filemanager on another queue than ioQueue, but we are using the shared instance
|
// this is an exception to access the filemanager on another queue than ioQueue, but we are using the shared instance
|
||||||
|
|
@ -287,20 +287,20 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
||||||
// checking the key with and without the extension
|
// checking the key with and without the extension
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
exists = [[NSFileManager defaultManager] fileExistsAtPath:[[self defaultCachePathForKey:key] stringByDeletingPathExtension]];
|
exists = [[NSFileManager defaultManager] fileExistsAtPath:[self defaultCachePathForKey:key].stringByDeletingPathExtension];
|
||||||
}
|
}
|
||||||
|
|
||||||
return exists;
|
return exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock {
|
- (void)diskImageExistsWithKey:(nullable NSString *)key completion:(nullable SDWebImageCheckCacheCompletionBlock)completionBlock {
|
||||||
dispatch_async(_ioQueue, ^{
|
dispatch_async(_ioQueue, ^{
|
||||||
BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]];
|
BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]];
|
||||||
|
|
||||||
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
||||||
// checking the key with and without the extension
|
// checking the key with and without the extension
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
exists = [_fileManager fileExistsAtPath:[[self defaultCachePathForKey:key] stringByDeletingPathExtension]];
|
exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key].stringByDeletingPathExtension];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (completionBlock) {
|
if (completionBlock) {
|
||||||
|
|
@ -311,11 +311,11 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIImage *)imageFromMemoryCacheForKey:(NSString *)key {
|
- (nullable UIImage *)imageFromMemoryCacheForKey:(nullable NSString *)key {
|
||||||
return [self.memCache objectForKey:key];
|
return [self.memCache objectForKey:key];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIImage *)imageFromDiskCacheForKey:(NSString *)key {
|
- (nullable UIImage *)imageFromDiskCacheForKey:(nullable NSString *)key {
|
||||||
|
|
||||||
// First check the in-memory cache...
|
// First check the in-memory cache...
|
||||||
UIImage *image = [self imageFromMemoryCacheForKey:key];
|
UIImage *image = [self imageFromMemoryCacheForKey:key];
|
||||||
|
|
@ -333,7 +333,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
return diskImage;
|
return diskImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSData *)diskImageDataBySearchingAllPathsForKey:(NSString *)key {
|
- (nullable NSData *)diskImageDataBySearchingAllPathsForKey:(nullable NSString *)key {
|
||||||
NSString *defaultPath = [self defaultCachePathForKey:key];
|
NSString *defaultPath = [self defaultCachePathForKey:key];
|
||||||
NSData *data = [NSData dataWithContentsOfFile:defaultPath];
|
NSData *data = [NSData dataWithContentsOfFile:defaultPath];
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|
@ -342,12 +342,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
|
|
||||||
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
||||||
// checking the key with and without the extension
|
// checking the key with and without the extension
|
||||||
data = [NSData dataWithContentsOfFile:[defaultPath stringByDeletingPathExtension]];
|
data = [NSData dataWithContentsOfFile:defaultPath.stringByDeletingPathExtension];
|
||||||
if (data) {
|
if (data) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSArray *customPaths = [self.customPaths copy];
|
NSArray<NSString *> *customPaths = [self.customPaths copy];
|
||||||
for (NSString *path in customPaths) {
|
for (NSString *path in customPaths) {
|
||||||
NSString *filePath = [self cachePathForKey:key inPath:path];
|
NSString *filePath = [self cachePathForKey:key inPath:path];
|
||||||
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
|
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
|
||||||
|
|
@ -357,7 +357,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
|
|
||||||
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
|
||||||
// checking the key with and without the extension
|
// checking the key with and without the extension
|
||||||
imageData = [NSData dataWithContentsOfFile:[filePath stringByDeletingPathExtension]];
|
imageData = [NSData dataWithContentsOfFile:filePath.stringByDeletingPathExtension];
|
||||||
if (imageData) {
|
if (imageData) {
|
||||||
return imageData;
|
return imageData;
|
||||||
}
|
}
|
||||||
|
|
@ -366,7 +366,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIImage *)diskImageForKey:(NSString *)key {
|
- (nullable UIImage *)diskImageForKey:(nullable NSString *)key {
|
||||||
NSData *data = [self diskImageDataBySearchingAllPathsForKey:key];
|
NSData *data = [self diskImageDataBySearchingAllPathsForKey:key];
|
||||||
if (data) {
|
if (data) {
|
||||||
UIImage *image = [UIImage sd_imageWithData:data];
|
UIImage *image = [UIImage sd_imageWithData:data];
|
||||||
|
|
@ -381,24 +381,28 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIImage *)scaledImageForKey:(NSString *)key image:(UIImage *)image {
|
- (nullable UIImage *)scaledImageForKey:(nullable NSString *)key image:(nullable UIImage *)image {
|
||||||
return SDScaledImageForKey(key, image);
|
return SDScaledImageForKey(key, image);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock {
|
- (nullable NSOperation *)queryDiskCacheForKey:(nullable NSString *)key done:(nullable SDCacheQueryCompletedBlock)doneBlock {
|
||||||
if (!doneBlock) {
|
if (!doneBlock) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!key) {
|
if (!key) {
|
||||||
doneBlock(nil, SDImageCacheTypeNone);
|
doneBlock(nil, nil, SDImageCacheTypeNone);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First check the in-memory cache...
|
// First check the in-memory cache...
|
||||||
UIImage *image = [self imageFromMemoryCacheForKey:key];
|
UIImage *image = [self imageFromMemoryCacheForKey:key];
|
||||||
if (image) {
|
if (image) {
|
||||||
doneBlock(image, SDImageCacheTypeMemory);
|
NSData *diskData = nil;
|
||||||
|
if ([image isGIF]) {
|
||||||
|
diskData = [self diskImageDataBySearchingAllPathsForKey:key];
|
||||||
|
}
|
||||||
|
doneBlock(image, diskData, SDImageCacheTypeMemory);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -409,6 +413,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
|
NSData *diskData = [self diskImageDataBySearchingAllPathsForKey:key];
|
||||||
UIImage *diskImage = [self diskImageForKey:key];
|
UIImage *diskImage = [self diskImageForKey:key];
|
||||||
if (diskImage && self.shouldCacheImagesInMemory) {
|
if (diskImage && self.shouldCacheImagesInMemory) {
|
||||||
NSUInteger cost = SDCacheCostForImage(diskImage);
|
NSUInteger cost = SDCacheCostForImage(diskImage);
|
||||||
|
|
@ -416,7 +421,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
doneBlock(diskImage, SDImageCacheTypeDisk);
|
doneBlock(diskImage, diskData, SDImageCacheTypeDisk);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -424,19 +429,19 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeImageForKey:(NSString *)key {
|
- (void)removeImageForKey:(nullable NSString *)key {
|
||||||
[self removeImageForKey:key withCompletion:nil];
|
[self removeImageForKey:key withCompletion:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion {
|
- (void)removeImageForKey:(nullable NSString *)key withCompletion:(nullable SDWebImageNoParamsBlock)completion {
|
||||||
[self removeImageForKey:key fromDisk:YES withCompletion:completion];
|
[self removeImageForKey:key fromDisk:YES withCompletion:completion];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk {
|
- (void)removeImageForKey:(nullable NSString *)key fromDisk:(BOOL)fromDisk {
|
||||||
[self removeImageForKey:key fromDisk:fromDisk withCompletion:nil];
|
[self removeImageForKey:key fromDisk:fromDisk withCompletion:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion {
|
- (void)removeImageForKey:(nullable NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(nullable SDWebImageNoParamsBlock)completion {
|
||||||
|
|
||||||
if (key == nil) {
|
if (key == nil) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -486,8 +491,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
[self clearDiskOnCompletion:nil];
|
[self clearDiskOnCompletion:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion
|
- (void)clearDiskOnCompletion:(nullable SDWebImageNoParamsBlock)completion {
|
||||||
{
|
|
||||||
dispatch_async(self.ioQueue, ^{
|
dispatch_async(self.ioQueue, ^{
|
||||||
[_fileManager removeItemAtPath:self.diskCachePath error:nil];
|
[_fileManager removeItemAtPath:self.diskCachePath error:nil];
|
||||||
[_fileManager createDirectoryAtPath:self.diskCachePath
|
[_fileManager createDirectoryAtPath:self.diskCachePath
|
||||||
|
|
@ -507,10 +511,10 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
[self cleanDiskWithCompletionBlock:nil];
|
[self cleanDiskWithCompletionBlock:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock {
|
- (void)cleanDiskWithCompletionBlock:(nullable SDWebImageNoParamsBlock)completionBlock {
|
||||||
dispatch_async(self.ioQueue, ^{
|
dispatch_async(self.ioQueue, ^{
|
||||||
NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES];
|
NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES];
|
||||||
NSArray *resourceKeys = @[NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey];
|
NSArray<NSString *> *resourceKeys = @[NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey];
|
||||||
|
|
||||||
// This enumerator prefetches useful properties for our cache files.
|
// This enumerator prefetches useful properties for our cache files.
|
||||||
NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtURL:diskCacheURL
|
NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtURL:diskCacheURL
|
||||||
|
|
@ -519,19 +523,19 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
errorHandler:NULL];
|
errorHandler:NULL];
|
||||||
|
|
||||||
NSDate *expirationDate = [NSDate dateWithTimeIntervalSinceNow:-self.maxCacheAge];
|
NSDate *expirationDate = [NSDate dateWithTimeIntervalSinceNow:-self.maxCacheAge];
|
||||||
NSMutableDictionary *cacheFiles = [NSMutableDictionary dictionary];
|
NSMutableDictionary<NSURL *, NSDictionary<NSString *, id> *> *cacheFiles = [NSMutableDictionary dictionary];
|
||||||
NSUInteger currentCacheSize = 0;
|
NSUInteger currentCacheSize = 0;
|
||||||
|
|
||||||
// Enumerate all of the files in the cache directory. This loop has two purposes:
|
// Enumerate all of the files in the cache directory. This loop has two purposes:
|
||||||
//
|
//
|
||||||
// 1. Removing files that are older than the expiration date.
|
// 1. Removing files that are older than the expiration date.
|
||||||
// 2. Storing file attributes for the size-based cleanup pass.
|
// 2. Storing file attributes for the size-based cleanup pass.
|
||||||
NSMutableArray *urlsToDelete = [[NSMutableArray alloc] init];
|
NSMutableArray<NSURL *> *urlsToDelete = [[NSMutableArray alloc] init];
|
||||||
for (NSURL *fileURL in fileEnumerator) {
|
for (NSURL *fileURL in fileEnumerator) {
|
||||||
NSDictionary *resourceValues = [fileURL resourceValuesForKeys:resourceKeys error:NULL];
|
NSDictionary<NSString *, id> *resourceValues = [fileURL resourceValuesForKeys:resourceKeys error:NULL];
|
||||||
|
|
||||||
// Skip nil or directories.
|
// Skip directories.
|
||||||
if (!resourceValues || [resourceValues[NSURLIsDirectoryKey] boolValue]) {
|
if ([resourceValues[NSURLIsDirectoryKey] boolValue]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -544,8 +548,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
|
|
||||||
// Store a reference to this file and account for its total size.
|
// Store a reference to this file and account for its total size.
|
||||||
NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey];
|
NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey];
|
||||||
currentCacheSize += [totalAllocatedSize unsignedIntegerValue];
|
currentCacheSize += totalAllocatedSize.unsignedIntegerValue;
|
||||||
[cacheFiles setObject:resourceValues forKey:fileURL];
|
cacheFiles[fileURL] = resourceValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (NSURL *fileURL in urlsToDelete) {
|
for (NSURL *fileURL in urlsToDelete) {
|
||||||
|
|
@ -559,17 +563,17 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
const NSUInteger desiredCacheSize = self.maxCacheSize / 2;
|
const NSUInteger desiredCacheSize = self.maxCacheSize / 2;
|
||||||
|
|
||||||
// Sort the remaining cache files by their last modification time (oldest first).
|
// Sort the remaining cache files by their last modification time (oldest first).
|
||||||
NSArray *sortedFiles = [cacheFiles keysSortedByValueWithOptions:NSSortConcurrent
|
NSArray<NSURL *> *sortedFiles = [cacheFiles keysSortedByValueWithOptions:NSSortConcurrent
|
||||||
usingComparator:^NSComparisonResult(id obj1, id obj2) {
|
usingComparator:^NSComparisonResult(id obj1, id obj2) {
|
||||||
return [obj1[NSURLContentModificationDateKey] compare:obj2[NSURLContentModificationDateKey]];
|
return [obj1[NSURLContentModificationDateKey] compare:obj2[NSURLContentModificationDateKey]];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
// Delete files until we fall below our desired cache size.
|
// Delete files until we fall below our desired cache size.
|
||||||
for (NSURL *fileURL in sortedFiles) {
|
for (NSURL *fileURL in sortedFiles) {
|
||||||
if ([_fileManager removeItemAtURL:fileURL error:nil]) {
|
if ([_fileManager removeItemAtURL:fileURL error:nil]) {
|
||||||
NSDictionary *resourceValues = cacheFiles[fileURL];
|
NSDictionary<NSString *, id> *resourceValues = cacheFiles[fileURL];
|
||||||
NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey];
|
NSNumber *totalAllocatedSize = resourceValues[NSURLTotalFileAllocatedSizeKey];
|
||||||
currentCacheSize -= [totalAllocatedSize unsignedIntegerValue];
|
currentCacheSize -= totalAllocatedSize.unsignedIntegerValue;
|
||||||
|
|
||||||
if (currentCacheSize < desiredCacheSize) {
|
if (currentCacheSize < desiredCacheSize) {
|
||||||
break;
|
break;
|
||||||
|
|
@ -611,7 +615,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath];
|
NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath];
|
||||||
for (NSString *fileName in fileEnumerator) {
|
for (NSString *fileName in fileEnumerator) {
|
||||||
NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName];
|
NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName];
|
||||||
NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
|
NSDictionary<NSString *, id> *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
|
||||||
size += [attrs fileSize];
|
size += [attrs fileSize];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -622,12 +626,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
__block NSUInteger count = 0;
|
__block NSUInteger count = 0;
|
||||||
dispatch_sync(self.ioQueue, ^{
|
dispatch_sync(self.ioQueue, ^{
|
||||||
NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath];
|
NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath];
|
||||||
count = [[fileEnumerator allObjects] count];
|
count = fileEnumerator.allObjects.count;
|
||||||
});
|
});
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock {
|
- (void)calculateSizeWithCompletionBlock:(nullable SDWebImageCalculateSizeBlock)completionBlock {
|
||||||
NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES];
|
NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES];
|
||||||
|
|
||||||
dispatch_async(self.ioQueue, ^{
|
dispatch_async(self.ioQueue, ^{
|
||||||
|
|
@ -642,7 +646,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
for (NSURL *fileURL in fileEnumerator) {
|
for (NSURL *fileURL in fileEnumerator) {
|
||||||
NSNumber *fileSize;
|
NSNumber *fileSize;
|
||||||
[fileURL getResourceValue:&fileSize forKey:NSURLFileSizeKey error:NULL];
|
[fileURL getResourceValue:&fileSize forKey:NSURLFileSizeKey error:NULL];
|
||||||
totalSize += [fileSize unsignedIntegerValue];
|
totalSize += fileSize.unsignedIntegerValue;
|
||||||
fileCount += 1;
|
fileCount += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
//
|
/*
|
||||||
// SDWebImageCompat.m
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Olivier Poitrey on 11/12/12.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
// Copyright (c) 2012 Dailymotion. All rights reserved.
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#import "SDWebImageCompat.h"
|
#import "SDWebImageCompat.h"
|
||||||
|
|
||||||
|
|
@ -12,13 +12,13 @@
|
||||||
#error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag
|
#error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) {
|
inline UIImage *SDScaledImageForKey(NSString * _Nullable key, UIImage * _Nullable image) {
|
||||||
if (!image) {
|
if (!image) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([image.images count] > 0) {
|
if ((image.images).count > 0) {
|
||||||
NSMutableArray *scaledImages = [NSMutableArray array];
|
NSMutableArray<UIImage *> *scaledImages = [NSMutableArray array];
|
||||||
|
|
||||||
for (UIImage *tempImage in image.images) {
|
for (UIImage *tempImage in image.images) {
|
||||||
[scaledImages addObject:SDScaledImageForKey(key, tempImage)];
|
[scaledImages addObject:SDScaledImageForKey(key, tempImage)];
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* This file is part of the SDWebImage package.
|
* This file is part of the SDWebImage package.
|
||||||
* (c) Olivier Poitrey <rs@dailymotion.com>
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
*
|
* (c) james <https://github.com/mystcolor>
|
||||||
* Created by james <https://github.com/mystcolor> on 9/28/11.
|
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|
@ -13,6 +12,6 @@
|
||||||
|
|
||||||
@interface UIImage (ForceDecode)
|
@interface UIImage (ForceDecode)
|
||||||
|
|
||||||
+ (UIImage *)decodedImageWithImage:(UIImage *)image;
|
+ (nullable UIImage *)decodedImageWithImage:(nullable UIImage *)image;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* This file is part of the SDWebImage package.
|
* This file is part of the SDWebImage package.
|
||||||
* (c) Olivier Poitrey <rs@dailymotion.com>
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
*
|
* (c) james <https://github.com/mystcolor>
|
||||||
* Created by james <https://github.com/mystcolor> on 9/28/11.
|
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
|
@ -12,7 +11,7 @@
|
||||||
|
|
||||||
@implementation UIImage (ForceDecode)
|
@implementation UIImage (ForceDecode)
|
||||||
|
|
||||||
+ (UIImage *)decodedImageWithImage:(UIImage *)image {
|
+ (nullable UIImage *)decodedImageWithImage:(nullable UIImage *)image {
|
||||||
// while downloading huge amount of images
|
// while downloading huge amount of images
|
||||||
// autorelease the bitmap context
|
// autorelease the bitmap context
|
||||||
// and all vars to help system to free memory
|
// and all vars to help system to free memory
|
||||||
|
|
|
||||||
|
|
@ -63,14 +63,28 @@ typedef NS_ENUM(NSInteger, SDWebImageDownloaderExecutionOrder) {
|
||||||
SDWebImageDownloaderLIFOExecutionOrder
|
SDWebImageDownloaderLIFOExecutionOrder
|
||||||
};
|
};
|
||||||
|
|
||||||
extern NSString *const SDWebImageDownloadStartNotification;
|
extern NSString * _Nonnull const SDWebImageDownloadStartNotification;
|
||||||
extern NSString *const SDWebImageDownloadStopNotification;
|
extern NSString * _Nonnull const SDWebImageDownloadStopNotification;
|
||||||
|
|
||||||
typedef void(^SDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize);
|
typedef void(^SDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize);
|
||||||
|
|
||||||
typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, NSError *error, BOOL finished);
|
typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished);
|
||||||
|
|
||||||
|
typedef NSDictionary<NSString *, NSString *> SDHTTPHeadersDictionary;
|
||||||
|
typedef NSMutableDictionary<NSString *, NSString *> SDHTTPHeadersMutableDictionary;
|
||||||
|
|
||||||
|
typedef SDHTTPHeadersDictionary * _Nullable (^SDWebImageDownloaderHeadersFilterBlock)(NSURL * _Nullable url, SDHTTPHeadersDictionary * _Nullable headers);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A token associated with each download. Can be used to cancel a download
|
||||||
|
*/
|
||||||
|
@interface SDWebImageDownloadToken : NSObject
|
||||||
|
|
||||||
|
@property (nonatomic, strong, nullable) NSURL *url;
|
||||||
|
@property (nonatomic, strong, nullable) id downloadOperationCancelToken;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDictionary *headers);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronous downloader dedicated and optimized for image loading.
|
* Asynchronous downloader dedicated and optimized for image loading.
|
||||||
|
|
@ -107,22 +121,22 @@ typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDi
|
||||||
*
|
*
|
||||||
* @return global shared instance of downloader class
|
* @return global shared instance of downloader class
|
||||||
*/
|
*/
|
||||||
+ (SDWebImageDownloader *)sharedDownloader;
|
+ (nonnull SDWebImageDownloader *)sharedDownloader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the default URL credential to be set for request operations.
|
* Set the default URL credential to be set for request operations.
|
||||||
*/
|
*/
|
||||||
@property (strong, nonatomic) NSURLCredential *urlCredential;
|
@property (strong, nonatomic, nullable) NSURLCredential *urlCredential;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set username
|
* Set username
|
||||||
*/
|
*/
|
||||||
@property (strong, nonatomic) NSString *username;
|
@property (strong, nonatomic, nullable) NSString *username;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set password
|
* Set password
|
||||||
*/
|
*/
|
||||||
@property (strong, nonatomic) NSString *password;
|
@property (strong, nonatomic, nullable) NSString *password;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set filter to pick headers for downloading image HTTP request.
|
* Set filter to pick headers for downloading image HTTP request.
|
||||||
|
|
@ -130,7 +144,7 @@ typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDi
|
||||||
* This block will be invoked for each downloading image request, returned
|
* This block will be invoked for each downloading image request, returned
|
||||||
* NSDictionary will be used as headers in corresponding HTTP request.
|
* NSDictionary will be used as headers in corresponding HTTP request.
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, copy) SDWebImageDownloaderHeadersFilterBlock headersFilter;
|
@property (nonatomic, copy, nullable) SDWebImageDownloaderHeadersFilterBlock headersFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a value for a HTTP header to be appended to each download HTTP request.
|
* Set a value for a HTTP header to be appended to each download HTTP request.
|
||||||
|
|
@ -138,14 +152,14 @@ typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDi
|
||||||
* @param value The value for the header field. Use `nil` value to remove the header.
|
* @param value The value for the header field. Use `nil` value to remove the header.
|
||||||
* @param field The name of the header field to set.
|
* @param field The name of the header field to set.
|
||||||
*/
|
*/
|
||||||
- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field;
|
- (void)setValue:(nullable NSString *)value forHTTPHeaderField:(nullable NSString *)field;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value of the specified HTTP header field.
|
* Returns the value of the specified HTTP header field.
|
||||||
*
|
*
|
||||||
* @return The value associated with the header field field, or `nil` if there is no corresponding header field.
|
* @return The value associated with the header field field, or `nil` if there is no corresponding header field.
|
||||||
*/
|
*/
|
||||||
- (NSString *)valueForHTTPHeaderField:(NSString *)field;
|
- (nullable NSString *)valueForHTTPHeaderField:(nullable NSString *)field;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a subclass of `SDWebImageDownloaderOperation` as the default
|
* Sets a subclass of `SDWebImageDownloaderOperation` as the default
|
||||||
|
|
@ -155,7 +169,7 @@ typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDi
|
||||||
* @param operationClass The subclass of `SDWebImageDownloaderOperation` to set
|
* @param operationClass The subclass of `SDWebImageDownloaderOperation` to set
|
||||||
* as default. Passing `nil` will revert to `SDWebImageDownloaderOperation`.
|
* as default. Passing `nil` will revert to `SDWebImageDownloaderOperation`.
|
||||||
*/
|
*/
|
||||||
- (void)setOperationClass:(Class)operationClass;
|
- (void)setOperationClass:(nullable Class)operationClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a SDWebImageDownloader async downloader instance with a given URL
|
* Creates a SDWebImageDownloader async downloader instance with a given URL
|
||||||
|
|
@ -176,12 +190,19 @@ typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDi
|
||||||
* before to be called a last time with the full image and finished argument
|
* before to be called a last time with the full image and finished argument
|
||||||
* set to YES. In case of error, the finished argument is always YES.
|
* set to YES. In case of error, the finished argument is always YES.
|
||||||
*
|
*
|
||||||
* @return A cancellable SDWebImageOperation
|
* @return A token (SDWebImageDownloadToken) that can be passed to -cancel: to cancel this operation
|
||||||
*/
|
*/
|
||||||
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
|
- (nullable SDWebImageDownloadToken *)downloadImageWithURL:(nullable NSURL *)url
|
||||||
options:(SDWebImageDownloaderOptions)options
|
options:(SDWebImageDownloaderOptions)options
|
||||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
completed:(SDWebImageDownloaderCompletedBlock)completedBlock;
|
completed:(nullable SDWebImageDownloaderCompletedBlock)completedBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels a download that was previously queued using -downloadImageWithURL:options:progress:completed:
|
||||||
|
*
|
||||||
|
* @param token The token received from -downloadImageWithURL:options:progress:completed: that should be canceled.
|
||||||
|
*/
|
||||||
|
- (void)cancel:(nullable SDWebImageDownloadToken *)token;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the download queue suspension state
|
* Sets the download queue suspension state
|
||||||
|
|
|
||||||
|
|
@ -10,18 +10,19 @@
|
||||||
#import "SDWebImageDownloaderOperation.h"
|
#import "SDWebImageDownloaderOperation.h"
|
||||||
#import <ImageIO/ImageIO.h>
|
#import <ImageIO/ImageIO.h>
|
||||||
|
|
||||||
static NSString *const kProgressCallbackKey = @"progress";
|
@implementation SDWebImageDownloadToken
|
||||||
static NSString *const kCompletedCallbackKey = @"completed";
|
@end
|
||||||
|
|
||||||
|
|
||||||
@interface SDWebImageDownloader () <NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
|
@interface SDWebImageDownloader () <NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
|
||||||
|
|
||||||
@property (strong, nonatomic) NSOperationQueue *downloadQueue;
|
@property (strong, nonatomic, nonnull) NSOperationQueue *downloadQueue;
|
||||||
@property (weak, nonatomic) NSOperation *lastAddedOperation;
|
@property (weak, nonatomic, nullable) NSOperation *lastAddedOperation;
|
||||||
@property (assign, nonatomic) Class operationClass;
|
@property (assign, nonatomic, nullable) Class operationClass;
|
||||||
@property (strong, nonatomic) NSMutableDictionary *URLCallbacks;
|
@property (strong, nonatomic, nonnull) NSMutableDictionary<NSURL *, SDWebImageDownloaderOperation *> *URLOperations;
|
||||||
@property (strong, nonatomic) NSMutableDictionary *HTTPHeaders;
|
@property (strong, nonatomic, nullable) SDHTTPHeadersMutableDictionary *HTTPHeaders;
|
||||||
// This queue is used to serialize the handling of the network responses of all the download operation in a single queue
|
// This queue is used to serialize the handling of the network responses of all the download operation in a single queue
|
||||||
@property (SDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t barrierQueue;
|
@property (SDDispatchQueueSetterSementics, nonatomic, nullable) dispatch_queue_t barrierQueue;
|
||||||
|
|
||||||
// The session in which data tasks will run
|
// The session in which data tasks will run
|
||||||
@property (strong, nonatomic) NSURLSession *session;
|
@property (strong, nonatomic) NSURLSession *session;
|
||||||
|
|
@ -53,7 +54,7 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (SDWebImageDownloader *)sharedDownloader {
|
+ (nonnull SDWebImageDownloader *)sharedDownloader {
|
||||||
static dispatch_once_t once;
|
static dispatch_once_t once;
|
||||||
static id instance;
|
static id instance;
|
||||||
dispatch_once(&once, ^{
|
dispatch_once(&once, ^{
|
||||||
|
|
@ -62,14 +63,14 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)init {
|
- (nonnull instancetype)init {
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
_operationClass = [SDWebImageDownloaderOperation class];
|
_operationClass = [SDWebImageDownloaderOperation class];
|
||||||
_shouldDecompressImages = YES;
|
_shouldDecompressImages = YES;
|
||||||
_executionOrder = SDWebImageDownloaderFIFOExecutionOrder;
|
_executionOrder = SDWebImageDownloaderFIFOExecutionOrder;
|
||||||
_downloadQueue = [NSOperationQueue new];
|
_downloadQueue = [NSOperationQueue new];
|
||||||
_downloadQueue.maxConcurrentOperationCount = 6;
|
_downloadQueue.maxConcurrentOperationCount = 6;
|
||||||
_URLCallbacks = [NSMutableDictionary new];
|
_URLOperations = [NSMutableDictionary new];
|
||||||
#ifdef SD_WEBP
|
#ifdef SD_WEBP
|
||||||
_HTTPHeaders = [@{@"Accept": @"image/webp,image/*;q=0.8"} mutableCopy];
|
_HTTPHeaders = [@{@"Accept": @"image/webp,image/*;q=0.8"} mutableCopy];
|
||||||
#else
|
#else
|
||||||
|
|
@ -101,7 +102,7 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
||||||
SDDispatchQueueRelease(_barrierQueue);
|
SDDispatchQueueRelease(_barrierQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field {
|
- (void)setValue:(nullable NSString *)value forHTTPHeaderField:(nullable NSString *)field {
|
||||||
if (value) {
|
if (value) {
|
||||||
self.HTTPHeaders[field] = value;
|
self.HTTPHeaders[field] = value;
|
||||||
}
|
}
|
||||||
|
|
@ -110,7 +111,7 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)valueForHTTPHeaderField:(NSString *)field {
|
- (nullable NSString *)valueForHTTPHeaderField:(nullable NSString *)field {
|
||||||
return self.HTTPHeaders[field];
|
return self.HTTPHeaders[field];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,16 +127,19 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
||||||
return _downloadQueue.maxConcurrentOperationCount;
|
return _downloadQueue.maxConcurrentOperationCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setOperationClass:(Class)operationClass {
|
- (void)setOperationClass:(nullable Class)operationClass {
|
||||||
_operationClass = operationClass ?: [SDWebImageDownloaderOperation class];
|
_operationClass = operationClass ?: [SDWebImageDownloaderOperation class];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock {
|
- (nullable SDWebImageDownloadToken *)downloadImageWithURL:(nullable NSURL *)url
|
||||||
__block SDWebImageDownloaderOperation *operation;
|
options:(SDWebImageDownloaderOptions)options
|
||||||
__weak __typeof(self)wself = self;
|
progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completed:(nullable SDWebImageDownloaderCompletedBlock)completedBlock {
|
||||||
|
__weak SDWebImageDownloader *wself = self;
|
||||||
|
|
||||||
[self addProgressCallback:progressBlock completedBlock:completedBlock forURL:url createCallback:^{
|
return [self addProgressCallback:progressBlock completedBlock:completedBlock forURL:url createCallback:^SDWebImageDownloaderOperation *{
|
||||||
NSTimeInterval timeoutInterval = wself.downloadTimeout;
|
__strong __typeof (wself) sself = wself;
|
||||||
|
NSTimeInterval timeoutInterval = sself.downloadTimeout;
|
||||||
if (timeoutInterval == 0.0) {
|
if (timeoutInterval == 0.0) {
|
||||||
timeoutInterval = 15.0;
|
timeoutInterval = 15.0;
|
||||||
}
|
}
|
||||||
|
|
@ -144,57 +148,19 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:timeoutInterval];
|
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:timeoutInterval];
|
||||||
request.HTTPShouldHandleCookies = (options & SDWebImageDownloaderHandleCookies);
|
request.HTTPShouldHandleCookies = (options & SDWebImageDownloaderHandleCookies);
|
||||||
request.HTTPShouldUsePipelining = YES;
|
request.HTTPShouldUsePipelining = YES;
|
||||||
if (wself.headersFilter) {
|
if (sself.headersFilter) {
|
||||||
request.allHTTPHeaderFields = wself.headersFilter(url, [wself.HTTPHeaders copy]);
|
request.allHTTPHeaderFields = sself.headersFilter(url, [sself.HTTPHeaders copy]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
request.allHTTPHeaderFields = wself.HTTPHeaders;
|
request.allHTTPHeaderFields = sself.HTTPHeaders;
|
||||||
}
|
}
|
||||||
operation = [[wself.operationClass alloc] initWithRequest:request
|
SDWebImageDownloaderOperation *operation = [[sself.operationClass alloc] initWithRequest:request inSession:sself.session options:options];
|
||||||
inSession:self.session
|
operation.shouldDecompressImages = sself.shouldDecompressImages;
|
||||||
options:options
|
|
||||||
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
|
||||||
SDWebImageDownloader *sself = wself;
|
|
||||||
if (!sself) return;
|
|
||||||
__block NSArray *callbacksForURL;
|
|
||||||
dispatch_sync(sself.barrierQueue, ^{
|
|
||||||
callbacksForURL = [sself.URLCallbacks[url] copy];
|
|
||||||
});
|
|
||||||
for (NSDictionary *callbacks in callbacksForURL) {
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey];
|
|
||||||
if (callback) callback(receivedSize, expectedSize);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
|
||||||
SDWebImageDownloader *sself = wself;
|
|
||||||
if (!sself) return;
|
|
||||||
__block NSArray *callbacksForURL;
|
|
||||||
dispatch_barrier_sync(sself.barrierQueue, ^{
|
|
||||||
callbacksForURL = [sself.URLCallbacks[url] copy];
|
|
||||||
if (finished) {
|
|
||||||
[sself.URLCallbacks removeObjectForKey:url];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
for (NSDictionary *callbacks in callbacksForURL) {
|
|
||||||
SDWebImageDownloaderCompletedBlock callback = callbacks[kCompletedCallbackKey];
|
|
||||||
if (callback) callback(image, data, error, finished);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cancelled:^{
|
|
||||||
SDWebImageDownloader *sself = wself;
|
|
||||||
if (!sself) return;
|
|
||||||
dispatch_barrier_async(sself.barrierQueue, ^{
|
|
||||||
[sself.URLCallbacks removeObjectForKey:url];
|
|
||||||
});
|
|
||||||
}];
|
|
||||||
operation.shouldDecompressImages = wself.shouldDecompressImages;
|
|
||||||
|
|
||||||
if (wself.urlCredential) {
|
if (sself.urlCredential) {
|
||||||
operation.credential = wself.urlCredential;
|
operation.credential = sself.urlCredential;
|
||||||
} else if (wself.username && wself.password) {
|
} else if (sself.username && sself.password) {
|
||||||
operation.credential = [NSURLCredential credentialWithUser:wself.username password:wself.password persistence:NSURLCredentialPersistenceForSession];
|
operation.credential = [NSURLCredential credentialWithUser:sself.username password:sself.password persistence:NSURLCredentialPersistenceForSession];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options & SDWebImageDownloaderHighPriority) {
|
if (options & SDWebImageDownloaderHighPriority) {
|
||||||
|
|
@ -203,49 +169,68 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
||||||
operation.queuePriority = NSOperationQueuePriorityLow;
|
operation.queuePriority = NSOperationQueuePriorityLow;
|
||||||
}
|
}
|
||||||
|
|
||||||
[wself.downloadQueue addOperation:operation];
|
[sself.downloadQueue addOperation:operation];
|
||||||
if (wself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) {
|
if (sself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) {
|
||||||
// Emulate LIFO execution order by systematically adding new operations as last operation's dependency
|
// Emulate LIFO execution order by systematically adding new operations as last operation's dependency
|
||||||
[wself.lastAddedOperation addDependency:operation];
|
[sself.lastAddedOperation addDependency:operation];
|
||||||
wself.lastAddedOperation = operation;
|
sself.lastAddedOperation = operation;
|
||||||
}
|
}
|
||||||
}];
|
|
||||||
|
|
||||||
return operation;
|
return operation;
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addProgressCallback:(SDWebImageDownloaderProgressBlock)progressBlock completedBlock:(SDWebImageDownloaderCompletedBlock)completedBlock forURL:(NSURL *)url createCallback:(SDWebImageNoParamsBlock)createCallback {
|
- (void)cancel:(nullable SDWebImageDownloadToken *)token {
|
||||||
|
dispatch_barrier_async(self.barrierQueue, ^{
|
||||||
|
SDWebImageDownloaderOperation *operation = self.URLOperations[token.url];
|
||||||
|
BOOL canceled = [operation cancel:token.downloadOperationCancelToken];
|
||||||
|
if (canceled) {
|
||||||
|
[self.URLOperations removeObjectForKey:token.url];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable SDWebImageDownloadToken *)addProgressCallback:(SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completedBlock:(SDWebImageDownloaderCompletedBlock)completedBlock
|
||||||
|
forURL:(nullable NSURL *)url
|
||||||
|
createCallback:(SDWebImageDownloaderOperation *(^)())createCallback {
|
||||||
// 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.
|
// 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.
|
||||||
if (url == nil) {
|
if (url == nil) {
|
||||||
if (completedBlock != nil) {
|
if (completedBlock != nil) {
|
||||||
completedBlock(nil, nil, nil, NO);
|
completedBlock(nil, nil, nil, NO);
|
||||||
}
|
}
|
||||||
return;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__block SDWebImageDownloadToken *token = nil;
|
||||||
|
|
||||||
dispatch_barrier_sync(self.barrierQueue, ^{
|
dispatch_barrier_sync(self.barrierQueue, ^{
|
||||||
BOOL first = NO;
|
SDWebImageDownloaderOperation *operation = self.URLOperations[url];
|
||||||
if (!self.URLCallbacks[url]) {
|
if (!operation) {
|
||||||
self.URLCallbacks[url] = [NSMutableArray new];
|
operation = createCallback();
|
||||||
first = YES;
|
self.URLOperations[url] = operation;
|
||||||
}
|
|
||||||
|
|
||||||
// Handle single download of simultaneous download request for the same URL
|
__weak SDWebImageDownloaderOperation *woperation = operation;
|
||||||
NSMutableArray *callbacksForURL = self.URLCallbacks[url];
|
operation.completionBlock = ^{
|
||||||
NSMutableDictionary *callbacks = [NSMutableDictionary new];
|
SDWebImageDownloaderOperation *soperation = woperation;
|
||||||
if (progressBlock) callbacks[kProgressCallbackKey] = [progressBlock copy];
|
if (!soperation) return;
|
||||||
if (completedBlock) callbacks[kCompletedCallbackKey] = [completedBlock copy];
|
if (self.URLOperations[url] == soperation) {
|
||||||
[callbacksForURL addObject:callbacks];
|
[self.URLOperations removeObjectForKey:url];
|
||||||
self.URLCallbacks[url] = callbacksForURL;
|
};
|
||||||
|
};
|
||||||
if (first) {
|
|
||||||
createCallback();
|
|
||||||
}
|
}
|
||||||
|
id downloadOperationCancelToken = [operation addHandlersForProgress:progressBlock completed:completedBlock];
|
||||||
|
|
||||||
|
token = [SDWebImageDownloadToken new];
|
||||||
|
token.url = url;
|
||||||
|
token.downloadOperationCancelToken = downloadOperationCancelToken;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setSuspended:(BOOL)suspended {
|
- (void)setSuspended:(BOOL)suspended {
|
||||||
[self.downloadQueue setSuspended:suspended];
|
(self.downloadQueue).suspended = suspended;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)cancelAllDownloads {
|
- (void)cancelAllDownloads {
|
||||||
|
|
|
||||||
|
|
@ -10,22 +10,22 @@
|
||||||
#import "SDWebImageDownloader.h"
|
#import "SDWebImageDownloader.h"
|
||||||
#import "SDWebImageOperation.h"
|
#import "SDWebImageOperation.h"
|
||||||
|
|
||||||
extern NSString *const SDWebImageDownloadStartNotification;
|
extern NSString * _Nonnull const SDWebImageDownloadStartNotification;
|
||||||
extern NSString *const SDWebImageDownloadReceiveResponseNotification;
|
extern NSString * _Nonnull const SDWebImageDownloadReceiveResponseNotification;
|
||||||
extern NSString *const SDWebImageDownloadStopNotification;
|
extern NSString * _Nonnull const SDWebImageDownloadStopNotification;
|
||||||
extern NSString *const SDWebImageDownloadFinishNotification;
|
extern NSString * _Nonnull const SDWebImageDownloadFinishNotification;
|
||||||
|
|
||||||
@interface SDWebImageDownloaderOperation : NSOperation <SDWebImageOperation, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
|
@interface SDWebImageDownloaderOperation : NSOperation <SDWebImageOperation, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The request used by the operation's task.
|
* The request used by the operation's task.
|
||||||
*/
|
*/
|
||||||
@property (strong, nonatomic, readonly) NSURLRequest *request;
|
@property (strong, nonatomic, readonly, nullable) NSURLRequest *request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The operation's task
|
* The operation's task
|
||||||
*/
|
*/
|
||||||
@property (strong, nonatomic, readonly) NSURLSessionTask *dataTask;
|
@property (strong, nonatomic, readonly, nullable) NSURLSessionTask *dataTask;
|
||||||
|
|
||||||
|
|
||||||
@property (assign, nonatomic) BOOL shouldDecompressImages;
|
@property (assign, nonatomic) BOOL shouldDecompressImages;
|
||||||
|
|
@ -41,7 +41,7 @@ extern NSString *const SDWebImageDownloadFinishNotification;
|
||||||
*
|
*
|
||||||
* This will be overridden by any shared credentials that exist for the username or password of the request URL, if present.
|
* This will be overridden by any shared credentials that exist for the username or password of the request URL, if present.
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, strong) NSURLCredential *credential;
|
@property (nonatomic, strong, nullable) NSURLCredential *credential;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SDWebImageDownloaderOptions for the receiver.
|
* The SDWebImageDownloaderOptions for the receiver.
|
||||||
|
|
@ -56,7 +56,7 @@ extern NSString *const SDWebImageDownloadFinishNotification;
|
||||||
/**
|
/**
|
||||||
* The response returned by the operation's connection.
|
* The response returned by the operation's connection.
|
||||||
*/
|
*/
|
||||||
@property (strong, nonatomic) NSURLResponse *response;
|
@property (strong, nonatomic, nullable) NSURLResponse *response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a `SDWebImageDownloaderOperation` object
|
* Initializes a `SDWebImageDownloaderOperation` object
|
||||||
|
|
@ -66,41 +66,34 @@ extern NSString *const SDWebImageDownloadFinishNotification;
|
||||||
* @param request the URL request
|
* @param request the URL request
|
||||||
* @param session the URL session in which this operation will run
|
* @param session the URL session in which this operation will run
|
||||||
* @param options downloader options
|
* @param options downloader options
|
||||||
* @param progressBlock the block executed when a new chunk of data arrives.
|
|
||||||
* @note the progress block is executed on a background queue
|
|
||||||
* @param completedBlock the block executed when the download is done.
|
|
||||||
* @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
|
|
||||||
* @param cancelBlock the block executed if the download (operation) is cancelled
|
|
||||||
*
|
*
|
||||||
* @return the initialized instance
|
* @return the initialized instance
|
||||||
*/
|
*/
|
||||||
- (id)initWithRequest:(NSURLRequest *)request
|
- (nonnull instancetype)initWithRequest:(nullable NSURLRequest *)request
|
||||||
inSession:(NSURLSession *)session
|
inSession:(nullable NSURLSession *)session
|
||||||
options:(SDWebImageDownloaderOptions)options
|
options:(SDWebImageDownloaderOptions)options NS_DESIGNATED_INITIALIZER;
|
||||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
|
||||||
completed:(SDWebImageDownloaderCompletedBlock)completedBlock
|
|
||||||
cancelled:(SDWebImageNoParamsBlock)cancelBlock;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a `SDWebImageDownloaderOperation` object
|
* Adds handlers for progress and completion. Returns a tokent that can be passed to -cancel: to cancel this set of
|
||||||
|
* callbacks.
|
||||||
*
|
*
|
||||||
* @see SDWebImageDownloaderOperation
|
|
||||||
*
|
|
||||||
* @param request the URL request
|
|
||||||
* @param options downloader options
|
|
||||||
* @param progressBlock the block executed when a new chunk of data arrives.
|
* @param progressBlock the block executed when a new chunk of data arrives.
|
||||||
* @note the progress block is executed on a background queue
|
* @note the progress block is executed on a background queue
|
||||||
* @param completedBlock the block executed when the download is done.
|
* @param completedBlock the block executed when the download is done.
|
||||||
* @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
|
* @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
|
||||||
* @param cancelBlock the block executed if the download (operation) is cancelled
|
|
||||||
*
|
*
|
||||||
* @return the initialized instance. The operation will run in a separate session created for this operation
|
* @return the token to use to cancel this set of handlers
|
||||||
*/
|
*/
|
||||||
- (id)initWithRequest:(NSURLRequest *)request
|
- (nullable id)addHandlersForProgress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
options:(SDWebImageDownloaderOptions)options
|
completed:(nullable SDWebImageDownloaderCompletedBlock)completedBlock;
|
||||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
|
||||||
completed:(SDWebImageDownloaderCompletedBlock)completedBlock
|
/**
|
||||||
cancelled:(SDWebImageNoParamsBlock)cancelBlock
|
* Cancels a set of callbacks. Once all callbacks are canceled, the operation is cancelled.
|
||||||
__deprecated_msg("Method deprecated. Use `initWithRequest:inSession:options:progress:completed:cancelled`");
|
*
|
||||||
|
* @param token the token representing a set of callbacks to cancel
|
||||||
|
*
|
||||||
|
* @return YES if the operation was stopped because this was the last token to be canceled. NO otherwise.
|
||||||
|
*/
|
||||||
|
- (BOOL)cancel:(nullable id)token;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -17,25 +17,29 @@ NSString *const SDWebImageDownloadReceiveResponseNotification = @"SDWebImageDown
|
||||||
NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNotification";
|
NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNotification";
|
||||||
NSString *const SDWebImageDownloadFinishNotification = @"SDWebImageDownloadFinishNotification";
|
NSString *const SDWebImageDownloadFinishNotification = @"SDWebImageDownloadFinishNotification";
|
||||||
|
|
||||||
|
static NSString *const kProgressCallbackKey = @"progress";
|
||||||
|
static NSString *const kCompletedCallbackKey = @"completed";
|
||||||
|
|
||||||
|
typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
|
||||||
|
|
||||||
@interface SDWebImageDownloaderOperation ()
|
@interface SDWebImageDownloaderOperation ()
|
||||||
|
|
||||||
@property (copy, nonatomic) SDWebImageDownloaderProgressBlock progressBlock;
|
@property (strong, nonatomic, nonnull) NSMutableArray<SDCallbacksDictionary *> *callbackBlocks;
|
||||||
@property (copy, nonatomic) SDWebImageDownloaderCompletedBlock completedBlock;
|
|
||||||
@property (copy, nonatomic) SDWebImageNoParamsBlock cancelBlock;
|
|
||||||
|
|
||||||
@property (assign, nonatomic, getter = isExecuting) BOOL executing;
|
@property (assign, nonatomic, getter = isExecuting) BOOL executing;
|
||||||
@property (assign, nonatomic, getter = isFinished) BOOL finished;
|
@property (assign, nonatomic, getter = isFinished) BOOL finished;
|
||||||
@property (strong, nonatomic) NSMutableData *imageData;
|
@property (strong, nonatomic, nullable) NSMutableData *imageData;
|
||||||
|
|
||||||
// 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
|
// 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
|
||||||
// the task associated with this operation
|
// the task associated with this operation
|
||||||
@property (weak, nonatomic) NSURLSession *unownedSession;
|
@property (weak, nonatomic, nullable) NSURLSession *unownedSession;
|
||||||
// This is set if we're using not using an injected NSURLSession. We're responsible of invalidating this one
|
// This is set if we're using not using an injected NSURLSession. We're responsible of invalidating this one
|
||||||
@property (strong, nonatomic) NSURLSession *ownedSession;
|
@property (strong, nonatomic, nullable) NSURLSession *ownedSession;
|
||||||
|
|
||||||
@property (strong, nonatomic, readwrite) NSURLSessionTask *dataTask;
|
@property (strong, nonatomic, readwrite, nullable) NSURLSessionTask *dataTask;
|
||||||
|
|
||||||
@property (strong, atomic) NSThread *thread;
|
@property (strong, atomic, nullable) NSThread *thread;
|
||||||
|
@property (SDDispatchQueueSetterSementics, nonatomic, nullable) dispatch_queue_t barrierQueue;
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
|
#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
|
||||||
@property (assign, nonatomic) UIBackgroundTaskIdentifier backgroundTaskId;
|
@property (assign, nonatomic) UIBackgroundTaskIdentifier backgroundTaskId;
|
||||||
|
|
@ -52,42 +56,67 @@ NSString *const SDWebImageDownloadFinishNotification = @"SDWebImageDownloadFinis
|
||||||
@synthesize executing = _executing;
|
@synthesize executing = _executing;
|
||||||
@synthesize finished = _finished;
|
@synthesize finished = _finished;
|
||||||
|
|
||||||
- (id)initWithRequest:(NSURLRequest *)request
|
- (nonnull instancetype)init {
|
||||||
options:(SDWebImageDownloaderOptions)options
|
return [self initWithRequest:nil inSession:nil options:0];
|
||||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
|
||||||
completed:(SDWebImageDownloaderCompletedBlock)completedBlock
|
|
||||||
cancelled:(SDWebImageNoParamsBlock)cancelBlock {
|
|
||||||
|
|
||||||
return [self initWithRequest:request
|
|
||||||
inSession:nil
|
|
||||||
options:options
|
|
||||||
progress:progressBlock
|
|
||||||
completed:completedBlock
|
|
||||||
cancelled:cancelBlock];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithRequest:(NSURLRequest *)request
|
- (nonnull instancetype)initWithRequest:(nullable NSURLRequest *)request
|
||||||
inSession:(NSURLSession *)session
|
inSession:(nullable NSURLSession *)session
|
||||||
options:(SDWebImageDownloaderOptions)options
|
options:(SDWebImageDownloaderOptions)options {
|
||||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
|
||||||
completed:(SDWebImageDownloaderCompletedBlock)completedBlock
|
|
||||||
cancelled:(SDWebImageNoParamsBlock)cancelBlock {
|
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
_request = request;
|
_request = request;
|
||||||
_shouldDecompressImages = YES;
|
_shouldDecompressImages = YES;
|
||||||
_options = options;
|
_options = options;
|
||||||
_progressBlock = [progressBlock copy];
|
_callbackBlocks = [NSMutableArray new];
|
||||||
_completedBlock = [completedBlock copy];
|
|
||||||
_cancelBlock = [cancelBlock copy];
|
|
||||||
_executing = NO;
|
_executing = NO;
|
||||||
_finished = NO;
|
_finished = NO;
|
||||||
_expectedSize = 0;
|
_expectedSize = 0;
|
||||||
_unownedSession = session;
|
_unownedSession = session;
|
||||||
responseFromCached = YES; // Initially wrong until `- URLSession:dataTask:willCacheResponse:completionHandler: is called or not called
|
responseFromCached = YES; // Initially wrong until `- URLSession:dataTask:willCacheResponse:completionHandler: is called or not called
|
||||||
|
_barrierQueue = dispatch_queue_create("com.hackemist.SDWebImageDownloaderOperationBarrierQueue", DISPATCH_QUEUE_CONCURRENT);
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)dealloc {
|
||||||
|
SDDispatchQueueRelease(_barrierQueue);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable id)addHandlersForProgress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completed:(nullable SDWebImageDownloaderCompletedBlock)completedBlock {
|
||||||
|
SDCallbacksDictionary *callbacks = [NSMutableDictionary new];
|
||||||
|
if (progressBlock) callbacks[kProgressCallbackKey] = [progressBlock copy];
|
||||||
|
if (completedBlock) callbacks[kCompletedCallbackKey] = [completedBlock copy];
|
||||||
|
dispatch_barrier_async(self.barrierQueue, ^{
|
||||||
|
[self.callbackBlocks addObject:callbacks];
|
||||||
|
});
|
||||||
|
return callbacks;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable NSArray<id> *)callbacksForKey:(NSString *)key {
|
||||||
|
__block NSMutableArray<id> *callbacks = nil;
|
||||||
|
dispatch_sync(self.barrierQueue, ^{
|
||||||
|
// We need to remove [NSNull null] because there might not always be a progress block for each callback
|
||||||
|
callbacks = [[self.callbackBlocks valueForKey:key] mutableCopy];
|
||||||
|
[callbacks removeObjectIdenticalTo:[NSNull null]];
|
||||||
|
});
|
||||||
|
return callbacks;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)cancel:(nullable id)token {
|
||||||
|
__block BOOL shouldCancel = NO;
|
||||||
|
dispatch_barrier_sync(self.barrierQueue, ^{
|
||||||
|
[self.callbackBlocks removeObjectIdenticalTo:token];
|
||||||
|
if (self.callbackBlocks.count == 0) {
|
||||||
|
shouldCancel = YES;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (shouldCancel) {
|
||||||
|
[self cancel];
|
||||||
|
}
|
||||||
|
return shouldCancel;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)start {
|
- (void)start {
|
||||||
@synchronized (self) {
|
@synchronized (self) {
|
||||||
if (self.isCancelled) {
|
if (self.isCancelled) {
|
||||||
|
|
@ -138,16 +167,15 @@ NSString *const SDWebImageDownloadFinishNotification = @"SDWebImageDownloadFinis
|
||||||
[self.dataTask resume];
|
[self.dataTask resume];
|
||||||
|
|
||||||
if (self.dataTask) {
|
if (self.dataTask) {
|
||||||
if (self.progressBlock) {
|
for (SDWebImageDownloaderProgressBlock progressBlock in [self callbacksForKey:kProgressCallbackKey]) {
|
||||||
self.progressBlock(0, NSURLResponseUnknownLength);
|
progressBlock(0, NSURLResponseUnknownLength);
|
||||||
}
|
}
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStartNotification object:self];
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStartNotification object:self];
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else {
|
for (SDWebImageDownloaderCompletedBlock completedBlock in [self callbacksForKey:kCompletedCallbackKey]) {
|
||||||
if (self.completedBlock) {
|
completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Connection can't be initialized"}], YES);
|
||||||
self.completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Connection can't be initialized"}], YES);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -183,7 +211,6 @@ NSString *const SDWebImageDownloadFinishNotification = @"SDWebImageDownloadFinis
|
||||||
- (void)cancelInternal {
|
- (void)cancelInternal {
|
||||||
if (self.isFinished) return;
|
if (self.isFinished) return;
|
||||||
[super cancel];
|
[super cancel];
|
||||||
if (self.cancelBlock) self.cancelBlock();
|
|
||||||
|
|
||||||
if (self.dataTask) {
|
if (self.dataTask) {
|
||||||
[self.dataTask cancel];
|
[self.dataTask cancel];
|
||||||
|
|
@ -207,9 +234,9 @@ NSString *const SDWebImageDownloadFinishNotification = @"SDWebImageDownloadFinis
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)reset {
|
- (void)reset {
|
||||||
self.cancelBlock = nil;
|
dispatch_barrier_async(self.barrierQueue, ^{
|
||||||
self.completedBlock = nil;
|
[self.callbackBlocks removeAllObjects];
|
||||||
self.progressBlock = nil;
|
});
|
||||||
self.dataTask = nil;
|
self.dataTask = nil;
|
||||||
self.imageData = nil;
|
self.imageData = nil;
|
||||||
self.thread = nil;
|
self.thread = nil;
|
||||||
|
|
@ -243,11 +270,11 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
|
completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
|
||||||
|
|
||||||
//'304 Not Modified' is an exceptional one
|
//'304 Not Modified' is an exceptional one
|
||||||
if (![response respondsToSelector:@selector(statusCode)] || ([((NSHTTPURLResponse *)response) statusCode] < 400 && [((NSHTTPURLResponse *)response) statusCode] != 304)) {
|
if (![response respondsToSelector:@selector(statusCode)] || (((NSHTTPURLResponse *)response).statusCode < 400 && ((NSHTTPURLResponse *)response).statusCode != 304)) {
|
||||||
NSInteger expected = response.expectedContentLength > 0 ? (NSInteger)response.expectedContentLength : 0;
|
NSInteger expected = response.expectedContentLength > 0 ? (NSInteger)response.expectedContentLength : 0;
|
||||||
self.expectedSize = expected;
|
self.expectedSize = expected;
|
||||||
if (self.progressBlock) {
|
for (SDWebImageDownloaderProgressBlock progressBlock in [self callbacksForKey:kProgressCallbackKey]) {
|
||||||
self.progressBlock(0, expected);
|
progressBlock(0, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.imageData = [[NSMutableData alloc] initWithCapacity:expected];
|
self.imageData = [[NSMutableData alloc] initWithCapacity:expected];
|
||||||
|
|
@ -257,7 +284,7 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
NSUInteger code = [((NSHTTPURLResponse *)response) statusCode];
|
NSUInteger code = ((NSHTTPURLResponse *)response).statusCode;
|
||||||
|
|
||||||
//This is the case when server returns '304 Not Modified'. It means that remote image is not changed.
|
//This is the case when server returns '304 Not Modified'. It means that remote image is not changed.
|
||||||
//In case of 304 we need just cancel the operation and return cached image from the cache.
|
//In case of 304 we need just cancel the operation and return cached image from the cache.
|
||||||
|
|
@ -269,9 +296,9 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
|
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];
|
||||||
});
|
});
|
||||||
|
|
||||||
if (self.completedBlock) {
|
for (SDWebImageDownloaderCompletedBlock completedBlock in [self callbacksForKey:kCompletedCallbackKey]) {
|
||||||
self.completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:[((NSHTTPURLResponse *)response) statusCode] userInfo:nil], YES);
|
completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:((NSHTTPURLResponse *)response).statusCode userInfo:nil], YES);
|
||||||
}
|
}
|
||||||
[self done];
|
[self done];
|
||||||
}
|
}
|
||||||
|
|
@ -284,7 +311,7 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
|
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
|
||||||
[self.imageData appendData:data];
|
[self.imageData appendData:data];
|
||||||
|
|
||||||
if ((self.options & SDWebImageDownloaderProgressiveDownload) && self.expectedSize > 0 && self.completedBlock) {
|
if ((self.options & SDWebImageDownloaderProgressiveDownload) && self.expectedSize > 0) {
|
||||||
// The following code is from http://www.cocoaintheshell.com/2011/05/progressive-images-download-imageio/
|
// The following code is from http://www.cocoaintheshell.com/2011/05/progressive-images-download-imageio/
|
||||||
// Thanks to the author @Nyx0uf
|
// Thanks to the author @Nyx0uf
|
||||||
|
|
||||||
|
|
@ -312,7 +339,6 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
// in didCompleteWithError.) So save it here and pass it on later.
|
// in didCompleteWithError.) So save it here and pass it on later.
|
||||||
orientation = [[self class] orientationFromPropertyValue:(orientationValue == -1 ? 1 : orientationValue)];
|
orientation = [[self class] orientationFromPropertyValue:(orientationValue == -1 ? 1 : orientationValue)];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (width + height > 0 && totalSize < self.expectedSize) {
|
if (width + height > 0 && totalSize < self.expectedSize) {
|
||||||
|
|
@ -351,8 +377,8 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
}
|
}
|
||||||
CGImageRelease(partialImageRef);
|
CGImageRelease(partialImageRef);
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
if (self.completedBlock) {
|
for (SDWebImageDownloaderCompletedBlock completedBlock in [self callbacksForKey:kCompletedCallbackKey]) {
|
||||||
self.completedBlock(image, nil, nil, NO);
|
completedBlock(image, nil, nil, NO);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -361,8 +387,8 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
CFRelease(imageSource);
|
CFRelease(imageSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.progressBlock) {
|
for (SDWebImageDownloaderProgressBlock progressBlock in [self callbacksForKey:kProgressCallbackKey]) {
|
||||||
self.progressBlock(self.imageData.length, self.expectedSize);
|
progressBlock(self.imageData.length, self.expectedSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -386,6 +412,7 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
#pragma mark NSURLSessionTaskDelegate
|
#pragma mark NSURLSessionTaskDelegate
|
||||||
|
|
||||||
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
|
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
|
||||||
|
NSArray<id> *completionBlocks = [[self callbacksForKey:kCompletedCallbackKey] copy];
|
||||||
@synchronized(self) {
|
@synchronized(self) {
|
||||||
self.thread = nil;
|
self.thread = nil;
|
||||||
self.dataTask = nil;
|
self.dataTask = nil;
|
||||||
|
|
@ -398,19 +425,19 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
if (self.completedBlock) {
|
for (SDWebImageDownloaderCompletedBlock completionBlock in completionBlocks) {
|
||||||
self.completedBlock(nil, nil, error, YES);
|
completionBlock(nil, nil, error, YES);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SDWebImageDownloaderCompletedBlock completionBlock = self.completedBlock;
|
|
||||||
|
|
||||||
if (![[NSURLCache sharedURLCache] cachedResponseForRequest:_request]) {
|
if (![[NSURLCache sharedURLCache] cachedResponseForRequest:_request]) {
|
||||||
responseFromCached = NO;
|
responseFromCached = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (completionBlock) {
|
if (completionBlocks.count > 0) {
|
||||||
if (self.options & SDWebImageDownloaderIgnoreCachedResponse && responseFromCached) {
|
if (self.options & SDWebImageDownloaderIgnoreCachedResponse && responseFromCached) {
|
||||||
completionBlock(nil, nil, nil, YES);
|
for (SDWebImageDownloaderCompletedBlock completionBlock in completionBlocks) {
|
||||||
|
completionBlock(nil, nil, nil, YES);
|
||||||
|
}
|
||||||
} else if (self.imageData) {
|
} else if (self.imageData) {
|
||||||
UIImage *image = [UIImage sd_imageWithData:self.imageData];
|
UIImage *image = [UIImage sd_imageWithData:self.imageData];
|
||||||
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL];
|
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL];
|
||||||
|
|
@ -423,18 +450,21 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (CGSizeEqualToSize(image.size, CGSizeZero)) {
|
if (CGSizeEqualToSize(image.size, CGSizeZero)) {
|
||||||
completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Downloaded image has 0 pixels"}], YES);
|
for (SDWebImageDownloaderCompletedBlock completionBlock in completionBlocks) {
|
||||||
}
|
completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Downloaded image has 0 pixels"}], YES);
|
||||||
else {
|
}
|
||||||
completionBlock(image, self.imageData, nil, YES);
|
} else {
|
||||||
|
for (SDWebImageDownloaderCompletedBlock completionBlock in completionBlocks) {
|
||||||
|
completionBlock(image, self.imageData, nil, YES);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Image data is nil"}], YES);
|
for (SDWebImageDownloaderCompletedBlock completionBlock in completionBlocks) {
|
||||||
|
completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Image data is nil"}], YES);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.completionBlock = nil;
|
|
||||||
[self done];
|
[self done];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -451,7 +481,7 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
disposition = NSURLSessionAuthChallengeUseCredential;
|
disposition = NSURLSessionAuthChallengeUseCredential;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ([challenge previousFailureCount] == 0) {
|
if (challenge.previousFailureCount == 0) {
|
||||||
if (self.credential) {
|
if (self.credential) {
|
||||||
credential = self.credential;
|
credential = self.credential;
|
||||||
disposition = NSURLSessionAuthChallengeUseCredential;
|
disposition = NSURLSessionAuthChallengeUseCredential;
|
||||||
|
|
@ -493,7 +523,7 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIImage *)scaledImageForKey:(NSString *)key image:(UIImage *)image {
|
- (nullable UIImage *)scaledImageForKey:(nullable NSString *)key image:(nullable UIImage *)image {
|
||||||
return SDScaledImageForKey(key, image);
|
return SDScaledImageForKey(key, image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,11 +90,11 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
|
||||||
SDWebImageAvoidAutoSetImage = 1 << 11
|
SDWebImageAvoidAutoSetImage = 1 << 11
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL);
|
typedef void(^SDExternalCompletionBlock)(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL);
|
||||||
|
|
||||||
typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL);
|
typedef void(^SDInternalCompletionBlock)(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL);
|
||||||
|
|
||||||
typedef NSString *(^SDWebImageCacheKeyFilterBlock)(NSURL *url);
|
typedef NSString * _Nullable (^SDWebImageCacheKeyFilterBlock)(NSURL * _Nullable url);
|
||||||
|
|
||||||
|
|
||||||
@class SDWebImageManager;
|
@class SDWebImageManager;
|
||||||
|
|
@ -111,7 +111,7 @@ typedef NSString *(^SDWebImageCacheKeyFilterBlock)(NSURL *url);
|
||||||
*
|
*
|
||||||
* @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied.
|
* @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied.
|
||||||
*/
|
*/
|
||||||
- (BOOL)imageManager:(SDWebImageManager *)imageManager shouldDownloadImageForURL:(NSURL *)imageURL;
|
- (BOOL)imageManager:(nonnull SDWebImageManager *)imageManager shouldDownloadImageForURL:(nullable NSURL *)imageURL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to transform the image immediately after it has been downloaded and just before to cache it on disk and memory.
|
* Allows to transform the image immediately after it has been downloaded and just before to cache it on disk and memory.
|
||||||
|
|
@ -123,7 +123,7 @@ typedef NSString *(^SDWebImageCacheKeyFilterBlock)(NSURL *url);
|
||||||
*
|
*
|
||||||
* @return The transformed image object.
|
* @return The transformed image object.
|
||||||
*/
|
*/
|
||||||
- (UIImage *)imageManager:(SDWebImageManager *)imageManager transformDownloadedImage:(UIImage *)image withURL:(NSURL *)imageURL;
|
- (nullable UIImage *)imageManager:(nonnull SDWebImageManager *)imageManager transformDownloadedImage:(nullable UIImage *)image withURL:(nullable NSURL *)imageURL;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
@ -138,23 +138,23 @@ typedef NSString *(^SDWebImageCacheKeyFilterBlock)(NSURL *url);
|
||||||
* @code
|
* @code
|
||||||
|
|
||||||
SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
[manager downloadImageWithURL:imageURL
|
[manager loadImageWithURL:imageURL
|
||||||
options:0
|
options:0
|
||||||
progress:nil
|
progress:nil
|
||||||
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
if (image) {
|
if (image) {
|
||||||
// do something with image
|
// do something with image
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
@interface SDWebImageManager : NSObject
|
@interface SDWebImageManager : NSObject
|
||||||
|
|
||||||
@property (weak, nonatomic) id <SDWebImageManagerDelegate> delegate;
|
@property (weak, nonatomic, nullable) id <SDWebImageManagerDelegate> delegate;
|
||||||
|
|
||||||
@property (strong, nonatomic, readonly) SDImageCache *imageCache;
|
@property (strong, nonatomic, readonly, nullable) SDImageCache *imageCache;
|
||||||
@property (strong, nonatomic, readonly) SDWebImageDownloader *imageDownloader;
|
@property (strong, nonatomic, readonly, nullable) SDWebImageDownloader *imageDownloader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The cache filter is a block used each time SDWebImageManager need to convert an URL into a cache key. This can
|
* The cache filter is a block used each time SDWebImageManager need to convert an URL into a cache key. This can
|
||||||
|
|
@ -172,20 +172,20 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
|
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, copy) SDWebImageCacheKeyFilterBlock cacheKeyFilter;
|
@property (nonatomic, copy, nullable) SDWebImageCacheKeyFilterBlock cacheKeyFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns global SDWebImageManager instance.
|
* Returns global SDWebImageManager instance.
|
||||||
*
|
*
|
||||||
* @return SDWebImageManager shared instance
|
* @return SDWebImageManager shared instance
|
||||||
*/
|
*/
|
||||||
+ (SDWebImageManager *)sharedManager;
|
+ (nonnull SDWebImageManager *)sharedManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to specify instance of cache and image downloader used with image manager.
|
* Allows to specify instance of cache and image downloader used with image manager.
|
||||||
* @return new instance of `SDWebImageManager` with specified cache and downloader.
|
* @return new instance of `SDWebImageManager` with specified cache and downloader.
|
||||||
*/
|
*/
|
||||||
- (instancetype)initWithCache:(SDImageCache *)cache downloader:(SDWebImageDownloader *)downloader;
|
- (nonnull instancetype)initWithCache:(nonnull SDImageCache *)cache downloader:(nonnull SDWebImageDownloader *)downloader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads the image at the given URL if not present in cache or return the cached version otherwise.
|
* Downloads the image at the given URL if not present in cache or return the cached version otherwise.
|
||||||
|
|
@ -197,22 +197,24 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
*
|
*
|
||||||
* This parameter is required.
|
* This parameter is required.
|
||||||
*
|
*
|
||||||
* This block has no return value and takes the requested UIImage as first parameter.
|
* This block has no return value and takes the requested UIImage as first parameter and the NSData representation as second parameter.
|
||||||
* In case of error the image parameter is nil and the second parameter may contain an NSError.
|
* In case of error the image parameter is nil and the third parameter may contain an NSError.
|
||||||
*
|
*
|
||||||
* The third parameter is an `SDImageCacheType` enum indicating if the image was retrieved from the local cache
|
* The forth parameter is an `SDImageCacheType` enum indicating if the image was retrieved from the local cache
|
||||||
* or from the memory cache or from the network.
|
* or from the memory cache or from the network.
|
||||||
*
|
*
|
||||||
* The last parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is
|
* The fith parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is
|
||||||
* downloading. This block is thus called repeatedly with a partial image. When image is fully downloaded, the
|
* downloading. This block is thus called repeatedly with a partial image. When image is fully downloaded, the
|
||||||
* block is called a last time with the full image and the last parameter set to YES.
|
* block is called a last time with the full image and the last parameter set to YES.
|
||||||
*
|
*
|
||||||
|
* The last parameter is the original image URL
|
||||||
|
*
|
||||||
* @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation
|
* @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation
|
||||||
*/
|
*/
|
||||||
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
|
- (nullable id <SDWebImageOperation>)loadImageWithURL:(nullable NSURL *)url
|
||||||
options:(SDWebImageOptions)options
|
options:(SDWebImageOptions)options
|
||||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
completed:(SDWebImageCompletionWithFinishedBlock)completedBlock;
|
completed:(nullable SDInternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves image to cache for given URL
|
* Saves image to cache for given URL
|
||||||
|
|
@ -222,7 +224,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
- (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url;
|
- (void)saveImageToCache:(nullable UIImage *)image forURL:(nullable NSURL *)url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel all current operations
|
* Cancel all current operations
|
||||||
|
|
@ -241,7 +243,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
*
|
*
|
||||||
* @return if the image was already cached
|
* @return if the image was already cached
|
||||||
*/
|
*/
|
||||||
- (BOOL)cachedImageExistsForURL:(NSURL *)url;
|
- (BOOL)cachedImageExistsForURL:(nullable NSURL *)url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if image has already been cached on disk only
|
* Check if image has already been cached on disk only
|
||||||
|
|
@ -250,7 +252,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
*
|
*
|
||||||
* @return if the image was already cached (disk only)
|
* @return if the image was already cached (disk only)
|
||||||
*/
|
*/
|
||||||
- (BOOL)diskImageExistsForURL:(NSURL *)url;
|
- (BOOL)diskImageExistsForURL:(nullable NSURL *)url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async check if image has already been cached
|
* Async check if image has already been cached
|
||||||
|
|
@ -260,8 +262,8 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
*
|
*
|
||||||
* @note the completion block is always executed on the main queue
|
* @note the completion block is always executed on the main queue
|
||||||
*/
|
*/
|
||||||
- (void)cachedImageExistsForURL:(NSURL *)url
|
- (void)cachedImageExistsForURL:(nullable NSURL *)url
|
||||||
completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;
|
completion:(nullable SDWebImageCheckCacheCompletionBlock)completionBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async check if image has already been cached on disk only
|
* Async check if image has already been cached on disk only
|
||||||
|
|
@ -271,34 +273,13 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
||||||
*
|
*
|
||||||
* @note the completion block is always executed on the main queue
|
* @note the completion block is always executed on the main queue
|
||||||
*/
|
*/
|
||||||
- (void)diskImageExistsForURL:(NSURL *)url
|
- (void)diskImageExistsForURL:(nullable NSURL *)url
|
||||||
completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;
|
completion:(nullable SDWebImageCheckCacheCompletionBlock)completionBlock;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Return the cache key for a given URL
|
*Return the cache key for a given URL
|
||||||
*/
|
*/
|
||||||
- (NSString *)cacheKeyForURL:(NSURL *)url;
|
- (nullable NSString *)cacheKeyForURL:(nullable NSURL *)url;
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - Deprecated
|
|
||||||
|
|
||||||
typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionBlock`");
|
|
||||||
typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionWithFinishedBlock`");
|
|
||||||
|
|
||||||
|
|
||||||
@interface SDWebImageManager (Deprecated)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Downloads the image at the given URL if not present in cache or return the cached version otherwise.
|
|
||||||
*
|
|
||||||
* @deprecated This method has been deprecated. Use `downloadImageWithURL:options:progress:completed:`
|
|
||||||
*/
|
|
||||||
- (id <SDWebImageOperation>)downloadWithURL:(NSURL *)url
|
|
||||||
options:(SDWebImageOptions)options
|
|
||||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
|
||||||
completed:(SDWebImageCompletedWithFinishedBlock)completedBlock __deprecated_msg("Method deprecated. Use `downloadImageWithURL:options:progress:completed:`");
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -12,23 +12,23 @@
|
||||||
@interface SDWebImageCombinedOperation : NSObject <SDWebImageOperation>
|
@interface SDWebImageCombinedOperation : NSObject <SDWebImageOperation>
|
||||||
|
|
||||||
@property (assign, nonatomic, getter = isCancelled) BOOL cancelled;
|
@property (assign, nonatomic, getter = isCancelled) BOOL cancelled;
|
||||||
@property (copy, nonatomic) SDWebImageNoParamsBlock cancelBlock;
|
@property (copy, nonatomic, nullable) SDWebImageNoParamsBlock cancelBlock;
|
||||||
@property (strong, nonatomic) NSOperation *cacheOperation;
|
@property (strong, nonatomic, nullable) NSOperation *cacheOperation;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface SDWebImageManager ()
|
@interface SDWebImageManager ()
|
||||||
|
|
||||||
@property (strong, nonatomic, readwrite) SDImageCache *imageCache;
|
@property (strong, nonatomic, readwrite, nonnull) SDImageCache *imageCache;
|
||||||
@property (strong, nonatomic, readwrite) SDWebImageDownloader *imageDownloader;
|
@property (strong, nonatomic, readwrite, nonnull) SDWebImageDownloader *imageDownloader;
|
||||||
@property (strong, nonatomic) NSMutableSet *failedURLs;
|
@property (strong, nonatomic, nonnull) NSMutableSet<NSURL *> *failedURLs;
|
||||||
@property (strong, nonatomic) NSMutableArray *runningOperations;
|
@property (strong, nonatomic, nonnull) NSMutableArray<SDWebImageCombinedOperation *> *runningOperations;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation SDWebImageManager
|
@implementation SDWebImageManager
|
||||||
|
|
||||||
+ (id)sharedManager {
|
+ (nonnull SDWebImageManager*)sharedManager {
|
||||||
static dispatch_once_t once;
|
static dispatch_once_t once;
|
||||||
static id instance;
|
static id instance;
|
||||||
dispatch_once(&once, ^{
|
dispatch_once(&once, ^{
|
||||||
|
|
@ -37,13 +37,13 @@
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)init {
|
- (nonnull instancetype)init {
|
||||||
SDImageCache *cache = [SDImageCache sharedImageCache];
|
SDImageCache *cache = [SDImageCache sharedImageCache];
|
||||||
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
|
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
|
||||||
return [self initWithCache:cache downloader:downloader];
|
return [self initWithCache:cache downloader:downloader];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithCache:(SDImageCache *)cache downloader:(SDWebImageDownloader *)downloader {
|
- (nonnull instancetype)initWithCache:(nonnull SDImageCache *)cache downloader:(nonnull SDWebImageDownloader *)downloader {
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
_imageCache = cache;
|
_imageCache = cache;
|
||||||
_imageDownloader = downloader;
|
_imageDownloader = downloader;
|
||||||
|
|
@ -53,31 +53,31 @@
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)cacheKeyForURL:(NSURL *)url {
|
- (nullable NSString *)cacheKeyForURL:(nullable NSURL *)url {
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return @"";
|
return @"";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.cacheKeyFilter) {
|
if (self.cacheKeyFilter) {
|
||||||
return self.cacheKeyFilter(url);
|
return self.cacheKeyFilter(url);
|
||||||
} else {
|
} else {
|
||||||
return [url absoluteString];
|
return url.absoluteString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)cachedImageExistsForURL:(NSURL *)url {
|
- (BOOL)cachedImageExistsForURL:(nullable NSURL *)url {
|
||||||
NSString *key = [self cacheKeyForURL:url];
|
NSString *key = [self cacheKeyForURL:url];
|
||||||
if ([self.imageCache imageFromMemoryCacheForKey:key] != nil) return YES;
|
if ([self.imageCache imageFromMemoryCacheForKey:key] != nil) return YES;
|
||||||
return [self.imageCache diskImageExistsWithKey:key];
|
return [self.imageCache diskImageExistsWithKey:key];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)diskImageExistsForURL:(NSURL *)url {
|
- (BOOL)diskImageExistsForURL:(nullable NSURL *)url {
|
||||||
NSString *key = [self cacheKeyForURL:url];
|
NSString *key = [self cacheKeyForURL:url];
|
||||||
return [self.imageCache diskImageExistsWithKey:key];
|
return [self.imageCache diskImageExistsWithKey:key];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)cachedImageExistsForURL:(NSURL *)url
|
- (void)cachedImageExistsForURL:(nullable NSURL *)url
|
||||||
completion:(SDWebImageCheckCacheCompletionBlock)completionBlock {
|
completion:(nullable SDWebImageCheckCacheCompletionBlock)completionBlock {
|
||||||
NSString *key = [self cacheKeyForURL:url];
|
NSString *key = [self cacheKeyForURL:url];
|
||||||
|
|
||||||
BOOL isInMemoryCache = ([self.imageCache imageFromMemoryCacheForKey:key] != nil);
|
BOOL isInMemoryCache = ([self.imageCache imageFromMemoryCacheForKey:key] != nil);
|
||||||
|
|
@ -100,8 +100,8 @@
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)diskImageExistsForURL:(NSURL *)url
|
- (void)diskImageExistsForURL:(nullable NSURL *)url
|
||||||
completion:(SDWebImageCheckCacheCompletionBlock)completionBlock {
|
completion:(nullable SDWebImageCheckCacheCompletionBlock)completionBlock {
|
||||||
NSString *key = [self cacheKeyForURL:url];
|
NSString *key = [self cacheKeyForURL:url];
|
||||||
|
|
||||||
[self.imageCache diskImageExistsWithKey:key completion:^(BOOL isInDiskCache) {
|
[self.imageCache diskImageExistsWithKey:key completion:^(BOOL isInDiskCache) {
|
||||||
|
|
@ -112,10 +112,10 @@
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
|
- (id <SDWebImageOperation>)loadImageWithURL:(nullable NSURL *)url
|
||||||
options:(SDWebImageOptions)options
|
options:(SDWebImageOptions)options
|
||||||
progress:(SDWebImageDownloaderProgressBlock)progressBlock
|
progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
completed:(SDWebImageCompletionWithFinishedBlock)completedBlock {
|
completed:(nullable SDInternalCompletionBlock)completedBlock {
|
||||||
// Invoking this method without a completedBlock is pointless
|
// Invoking this method without a completedBlock is pointless
|
||||||
NSAssert(completedBlock != nil, @"If you mean to prefetch the image, use -[SDWebImagePrefetcher prefetchURLs] instead");
|
NSAssert(completedBlock != nil, @"If you mean to prefetch the image, use -[SDWebImagePrefetcher prefetchURLs] instead");
|
||||||
|
|
||||||
|
|
@ -134,14 +134,16 @@
|
||||||
__weak SDWebImageCombinedOperation *weakOperation = operation;
|
__weak SDWebImageCombinedOperation *weakOperation = operation;
|
||||||
|
|
||||||
BOOL isFailedUrl = NO;
|
BOOL isFailedUrl = NO;
|
||||||
@synchronized (self.failedURLs) {
|
if (url) {
|
||||||
isFailedUrl = [self.failedURLs containsObject:url];
|
@synchronized (self.failedURLs) {
|
||||||
|
isFailedUrl = [self.failedURLs containsObject:url];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.absoluteString.length == 0 || (!(options & SDWebImageRetryFailed) && isFailedUrl)) {
|
if (url.absoluteString.length == 0 || (!(options & SDWebImageRetryFailed) && isFailedUrl)) {
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil];
|
NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil];
|
||||||
completedBlock(nil, error, SDImageCacheTypeNone, YES, url);
|
completedBlock(nil, nil, error, SDImageCacheTypeNone, YES, url);
|
||||||
});
|
});
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
@ -151,7 +153,7 @@
|
||||||
}
|
}
|
||||||
NSString *key = [self cacheKeyForURL:url];
|
NSString *key = [self cacheKeyForURL:url];
|
||||||
|
|
||||||
operation.cacheOperation = [self.imageCache queryDiskCacheForKey:key done:^(UIImage *image, SDImageCacheType cacheType) {
|
operation.cacheOperation = [self.imageCache queryDiskCacheForKey:key done:^(UIImage *cachedImage, NSData *cachedData, SDImageCacheType cacheType) {
|
||||||
if (operation.isCancelled) {
|
if (operation.isCancelled) {
|
||||||
@synchronized (self.runningOperations) {
|
@synchronized (self.runningOperations) {
|
||||||
[self.runningOperations removeObject:operation];
|
[self.runningOperations removeObject:operation];
|
||||||
|
|
@ -160,12 +162,12 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!image || options & SDWebImageRefreshCached) && (![self.delegate respondsToSelector:@selector(imageManager:shouldDownloadImageForURL:)] || [self.delegate imageManager:self shouldDownloadImageForURL:url])) {
|
if ((!cachedImage || options & SDWebImageRefreshCached) && (![self.delegate respondsToSelector:@selector(imageManager:shouldDownloadImageForURL:)] || [self.delegate imageManager:self shouldDownloadImageForURL:url])) {
|
||||||
if (image && options & SDWebImageRefreshCached) {
|
if (cachedImage && options & SDWebImageRefreshCached) {
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
// If image was found in the cache but SDWebImageRefreshCached is provided, notify about the cached image
|
// If image was found in the cache but SDWebImageRefreshCached is provided, notify about the cached image
|
||||||
// AND try to re-download it in order to let a chance to NSURLCache to refresh it from server.
|
// AND try to re-download it in order to let a chance to NSURLCache to refresh it from server.
|
||||||
completedBlock(image, nil, cacheType, YES, url);
|
completedBlock(cachedImage, cachedData, nil, cacheType, YES, url);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -178,23 +180,22 @@
|
||||||
if (options & SDWebImageHandleCookies) downloaderOptions |= SDWebImageDownloaderHandleCookies;
|
if (options & SDWebImageHandleCookies) downloaderOptions |= SDWebImageDownloaderHandleCookies;
|
||||||
if (options & SDWebImageAllowInvalidSSLCertificates) downloaderOptions |= SDWebImageDownloaderAllowInvalidSSLCertificates;
|
if (options & SDWebImageAllowInvalidSSLCertificates) downloaderOptions |= SDWebImageDownloaderAllowInvalidSSLCertificates;
|
||||||
if (options & SDWebImageHighPriority) downloaderOptions |= SDWebImageDownloaderHighPriority;
|
if (options & SDWebImageHighPriority) downloaderOptions |= SDWebImageDownloaderHighPriority;
|
||||||
if (image && options & SDWebImageRefreshCached) {
|
if (cachedImage && options & SDWebImageRefreshCached) {
|
||||||
// force progressive off if image already cached but forced refreshing
|
// force progressive off if image already cached but forced refreshing
|
||||||
downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;
|
downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;
|
||||||
// ignore image read from NSURLCache if image if cached but force refreshing
|
// ignore image read from NSURLCache if image if cached but force refreshing
|
||||||
downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
|
downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
|
||||||
}
|
}
|
||||||
id <SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished) {
|
id subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *downloadedData, NSError *error, BOOL finished) {
|
||||||
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
||||||
if (!strongOperation || strongOperation.isCancelled) {
|
if (!strongOperation || strongOperation.isCancelled) {
|
||||||
// Do nothing if the operation was cancelled
|
// Do nothing if the operation was cancelled
|
||||||
// See #699 for more details
|
// See #699 for more details
|
||||||
// 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
|
// 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
|
||||||
}
|
} else if (error) {
|
||||||
else if (error) {
|
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
if (strongOperation && !strongOperation.isCancelled) {
|
if (strongOperation && !strongOperation.isCancelled) {
|
||||||
completedBlock(nil, error, SDImageCacheTypeNone, finished, url);
|
completedBlock(nil, nil, error, SDImageCacheTypeNone, finished, url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -219,33 +220,31 @@
|
||||||
|
|
||||||
BOOL cacheOnDisk = !(options & SDWebImageCacheMemoryOnly);
|
BOOL cacheOnDisk = !(options & SDWebImageCacheMemoryOnly);
|
||||||
|
|
||||||
if (options & SDWebImageRefreshCached && image && !downloadedImage) {
|
if (options & SDWebImageRefreshCached && cachedImage && !downloadedImage) {
|
||||||
// Image refresh hit the NSURLCache cache, do not call the completion block
|
// Image refresh hit the NSURLCache cache, do not call the completion block
|
||||||
}
|
} else if (downloadedImage && (!downloadedImage.images || (options & SDWebImageTransformAnimatedImage)) && [self.delegate respondsToSelector:@selector(imageManager:transformDownloadedImage:withURL:)]) {
|
||||||
else if (downloadedImage && (!downloadedImage.images || (options & SDWebImageTransformAnimatedImage)) && [self.delegate respondsToSelector:@selector(imageManager:transformDownloadedImage:withURL:)]) {
|
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
|
||||||
UIImage *transformedImage = [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url];
|
UIImage *transformedImage = [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url];
|
||||||
|
|
||||||
if (transformedImage && finished) {
|
if (transformedImage && finished) {
|
||||||
BOOL imageWasTransformed = ![transformedImage isEqual:downloadedImage];
|
BOOL imageWasTransformed = ![transformedImage isEqual:downloadedImage];
|
||||||
[self.imageCache storeImage:transformedImage recalculateFromImage:imageWasTransformed imageData:(imageWasTransformed ? nil : data) forKey:key toDisk:cacheOnDisk];
|
[self.imageCache storeImage:transformedImage recalculateFromImage:imageWasTransformed imageData:(imageWasTransformed ? nil : downloadedData) forKey:key toDisk:cacheOnDisk];
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
if (strongOperation && !strongOperation.isCancelled) {
|
if (strongOperation && !strongOperation.isCancelled) {
|
||||||
completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished, url);
|
completedBlock(transformedImage, downloadedData, nil, SDImageCacheTypeNone, finished, url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (downloadedImage && finished) {
|
if (downloadedImage && finished) {
|
||||||
[self.imageCache storeImage:downloadedImage recalculateFromImage:NO imageData:data forKey:key toDisk:cacheOnDisk];
|
[self.imageCache storeImage:downloadedImage recalculateFromImage:NO imageData:downloadedData forKey:key toDisk:cacheOnDisk];
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
if (strongOperation && !strongOperation.isCancelled) {
|
if (strongOperation && !strongOperation.isCancelled) {
|
||||||
completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished, url);
|
completedBlock(downloadedImage, downloadedData, nil, SDImageCacheTypeNone, finished, url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -260,8 +259,8 @@
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
operation.cancelBlock = ^{
|
operation.cancelBlock = ^{
|
||||||
[subOperation cancel];
|
[self.imageDownloader cancel:subOperation];
|
||||||
|
|
||||||
@synchronized (self.runningOperations) {
|
@synchronized (self.runningOperations) {
|
||||||
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
||||||
if (strongOperation) {
|
if (strongOperation) {
|
||||||
|
|
@ -269,24 +268,22 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} else if (cachedImage) {
|
||||||
else if (image) {
|
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
||||||
if (strongOperation && !strongOperation.isCancelled) {
|
if (strongOperation && !strongOperation.isCancelled) {
|
||||||
completedBlock(image, nil, cacheType, YES, url);
|
completedBlock(cachedImage, cachedData, nil, cacheType, YES, url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@synchronized (self.runningOperations) {
|
@synchronized (self.runningOperations) {
|
||||||
[self.runningOperations removeObject:operation];
|
[self.runningOperations removeObject:operation];
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Image not in cache and download disallowed by delegate
|
// Image not in cache and download disallowed by delegate
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
||||||
if (strongOperation && !weakOperation.isCancelled) {
|
if (strongOperation && !weakOperation.isCancelled) {
|
||||||
completedBlock(nil, nil, SDImageCacheTypeNone, YES, url);
|
completedBlock(nil, nil, nil, SDImageCacheTypeNone, YES, url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@synchronized (self.runningOperations) {
|
@synchronized (self.runningOperations) {
|
||||||
|
|
@ -298,7 +295,7 @@
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url {
|
- (void)saveImageToCache:(nullable UIImage *)image forURL:(nullable NSURL *)url {
|
||||||
if (image && url) {
|
if (image && url) {
|
||||||
NSString *key = [self cacheKeyForURL:url];
|
NSString *key = [self cacheKeyForURL:url];
|
||||||
[self.imageCache storeImage:image forKey:key toDisk:YES];
|
[self.imageCache storeImage:image forKey:key toDisk:YES];
|
||||||
|
|
@ -307,7 +304,7 @@
|
||||||
|
|
||||||
- (void)cancelAll {
|
- (void)cancelAll {
|
||||||
@synchronized (self.runningOperations) {
|
@synchronized (self.runningOperations) {
|
||||||
NSArray *copiedOperations = [self.runningOperations copy];
|
NSArray<SDWebImageCombinedOperation *> *copiedOperations = [self.runningOperations copy];
|
||||||
[copiedOperations makeObjectsPerformSelector:@selector(cancel)];
|
[copiedOperations makeObjectsPerformSelector:@selector(cancel)];
|
||||||
[self.runningOperations removeObjectsInArray:copiedOperations];
|
[self.runningOperations removeObjectsInArray:copiedOperations];
|
||||||
}
|
}
|
||||||
|
|
@ -326,7 +323,7 @@
|
||||||
|
|
||||||
@implementation SDWebImageCombinedOperation
|
@implementation SDWebImageCombinedOperation
|
||||||
|
|
||||||
- (void)setCancelBlock:(SDWebImageNoParamsBlock)cancelBlock {
|
- (void)setCancelBlock:(nullable SDWebImageNoParamsBlock)cancelBlock {
|
||||||
// check if the operation is already cancelled, then we just call the cancelBlock
|
// check if the operation is already cancelled, then we just call the cancelBlock
|
||||||
if (self.isCancelled) {
|
if (self.isCancelled) {
|
||||||
if (cancelBlock) {
|
if (cancelBlock) {
|
||||||
|
|
@ -355,21 +352,3 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation SDWebImageManager (Deprecated)
|
|
||||||
|
|
||||||
// deprecated method, uses the non deprecated method
|
|
||||||
// adapter for the completion block
|
|
||||||
- (id <SDWebImageOperation>)downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock {
|
|
||||||
return [self downloadImageWithURL:url
|
|
||||||
options:options
|
|
||||||
progress:progressBlock
|
|
||||||
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType, finished);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
* @param finishedCount The total number of images that were prefetched (successful or not)
|
* @param finishedCount The total number of images that were prefetched (successful or not)
|
||||||
* @param totalCount The total number of images that were to be prefetched
|
* @param totalCount The total number of images that were to be prefetched
|
||||||
*/
|
*/
|
||||||
- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount;
|
- (void)imagePrefetcher:(nonnull SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(nullable NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when all images are prefetched.
|
* Called when all images are prefetched.
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
* @param totalCount The total number of images that were prefetched (whether successful or not)
|
* @param totalCount The total number of images that were prefetched (whether successful or not)
|
||||||
* @param skippedCount The total number of images that were skipped
|
* @param skippedCount The total number of images that were skipped
|
||||||
*/
|
*/
|
||||||
- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount;
|
- (void)imagePrefetcher:(nonnull SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
@ -46,7 +46,7 @@ typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls,
|
||||||
/**
|
/**
|
||||||
* The web image manager
|
* The web image manager
|
||||||
*/
|
*/
|
||||||
@property (strong, nonatomic, readonly) SDWebImageManager *manager;
|
@property (strong, nonatomic, readonly, nonnull) SDWebImageManager *manager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum number of URLs to prefetch at the same time. Defaults to 3.
|
* Maximum number of URLs to prefetch at the same time. Defaults to 3.
|
||||||
|
|
@ -61,19 +61,19 @@ typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls,
|
||||||
/**
|
/**
|
||||||
* Queue options for Prefetcher. Defaults to Main Queue.
|
* Queue options for Prefetcher. Defaults to Main Queue.
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, assign) dispatch_queue_t prefetcherQueue;
|
@property (nonatomic, assign, nonnull) dispatch_queue_t prefetcherQueue;
|
||||||
|
|
||||||
@property (weak, nonatomic) id <SDWebImagePrefetcherDelegate> delegate;
|
@property (weak, nonatomic, nullable) id <SDWebImagePrefetcherDelegate> delegate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the global image prefetcher instance.
|
* Return the global image prefetcher instance.
|
||||||
*/
|
*/
|
||||||
+ (SDWebImagePrefetcher *)sharedImagePrefetcher;
|
+ (nonnull SDWebImagePrefetcher *)sharedImagePrefetcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows you to instantiate a prefetcher with any arbitrary image manager.
|
* Allows you to instantiate a prefetcher with any arbitrary image manager.
|
||||||
*/
|
*/
|
||||||
- (id)initWithImageManager:(SDWebImageManager *)manager;
|
- (nonnull instancetype)initWithImageManager:(nonnull SDWebImageManager *)manager NS_DESIGNATED_INITIALIZER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
|
* Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
|
||||||
|
|
@ -82,7 +82,7 @@ typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls,
|
||||||
*
|
*
|
||||||
* @param urls list of URLs to prefetch
|
* @param urls list of URLs to prefetch
|
||||||
*/
|
*/
|
||||||
- (void)prefetchURLs:(NSArray *)urls;
|
- (void)prefetchURLs:(nullable NSArray<NSURL *> *)urls;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
|
* Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
|
||||||
|
|
@ -97,7 +97,9 @@ typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls,
|
||||||
* first param is the number of completed (successful or not) requests,
|
* first param is the number of completed (successful or not) requests,
|
||||||
* second parameter is the number of skipped requests
|
* second parameter is the number of skipped requests
|
||||||
*/
|
*/
|
||||||
- (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock;
|
- (void)prefetchURLs:(nullable NSArray<NSURL *> *)urls
|
||||||
|
progress:(nullable SDWebImagePrefetcherProgressBlock)progressBlock
|
||||||
|
completed:(nullable SDWebImagePrefetcherCompletionBlock)completionBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove and cancel queued list
|
* Remove and cancel queued list
|
||||||
|
|
|
||||||
|
|
@ -10,20 +10,20 @@
|
||||||
|
|
||||||
@interface SDWebImagePrefetcher ()
|
@interface SDWebImagePrefetcher ()
|
||||||
|
|
||||||
@property (strong, nonatomic) SDWebImageManager *manager;
|
@property (strong, nonatomic, nonnull) SDWebImageManager *manager;
|
||||||
@property (strong, nonatomic) NSArray *prefetchURLs;
|
@property (strong, nonatomic, nullable) NSArray<NSURL *> *prefetchURLs;
|
||||||
@property (assign, nonatomic) NSUInteger requestedCount;
|
@property (assign, nonatomic) NSUInteger requestedCount;
|
||||||
@property (assign, nonatomic) NSUInteger skippedCount;
|
@property (assign, nonatomic) NSUInteger skippedCount;
|
||||||
@property (assign, nonatomic) NSUInteger finishedCount;
|
@property (assign, nonatomic) NSUInteger finishedCount;
|
||||||
@property (assign, nonatomic) NSTimeInterval startedTime;
|
@property (assign, nonatomic) NSTimeInterval startedTime;
|
||||||
@property (copy, nonatomic) SDWebImagePrefetcherCompletionBlock completionBlock;
|
@property (copy, nonatomic, nullable) SDWebImagePrefetcherCompletionBlock completionBlock;
|
||||||
@property (copy, nonatomic) SDWebImagePrefetcherProgressBlock progressBlock;
|
@property (copy, nonatomic, nullable) SDWebImagePrefetcherProgressBlock progressBlock;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation SDWebImagePrefetcher
|
@implementation SDWebImagePrefetcher
|
||||||
|
|
||||||
+ (SDWebImagePrefetcher *)sharedImagePrefetcher {
|
+ (nonnull SDWebImagePrefetcher *)sharedImagePrefetcher {
|
||||||
static dispatch_once_t once;
|
static dispatch_once_t once;
|
||||||
static id instance;
|
static id instance;
|
||||||
dispatch_once(&once, ^{
|
dispatch_once(&once, ^{
|
||||||
|
|
@ -32,11 +32,11 @@
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)init {
|
- (nonnull instancetype)init {
|
||||||
return [self initWithImageManager:[SDWebImageManager new]];
|
return [self initWithImageManager:[SDWebImageManager new]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithImageManager:(SDWebImageManager *)manager {
|
- (nonnull instancetype)initWithImageManager:(SDWebImageManager *)manager {
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
_manager = manager;
|
_manager = manager;
|
||||||
_options = SDWebImageLowPriority;
|
_options = SDWebImageLowPriority;
|
||||||
|
|
@ -57,18 +57,18 @@
|
||||||
- (void)startPrefetchingAtIndex:(NSUInteger)index {
|
- (void)startPrefetchingAtIndex:(NSUInteger)index {
|
||||||
if (index >= self.prefetchURLs.count) return;
|
if (index >= self.prefetchURLs.count) return;
|
||||||
self.requestedCount++;
|
self.requestedCount++;
|
||||||
[self.manager downloadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
[self.manager loadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
if (!finished) return;
|
if (!finished) return;
|
||||||
self.finishedCount++;
|
self.finishedCount++;
|
||||||
|
|
||||||
if (image) {
|
if (image) {
|
||||||
if (self.progressBlock) {
|
if (self.progressBlock) {
|
||||||
self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
|
self.progressBlock(self.finishedCount,(self.prefetchURLs).count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (self.progressBlock) {
|
if (self.progressBlock) {
|
||||||
self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
|
self.progressBlock(self.finishedCount,(self.prefetchURLs).count);
|
||||||
}
|
}
|
||||||
// Add last failed
|
// Add last failed
|
||||||
self.skippedCount++;
|
self.skippedCount++;
|
||||||
|
|
@ -96,7 +96,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)reportStatus {
|
- (void)reportStatus {
|
||||||
NSUInteger total = [self.prefetchURLs count];
|
NSUInteger total = (self.prefetchURLs).count;
|
||||||
if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)]) {
|
if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)]) {
|
||||||
[self.delegate imagePrefetcher:self
|
[self.delegate imagePrefetcher:self
|
||||||
didFinishWithTotalCount:(total - self.skippedCount)
|
didFinishWithTotalCount:(total - self.skippedCount)
|
||||||
|
|
@ -105,11 +105,13 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)prefetchURLs:(NSArray *)urls {
|
- (void)prefetchURLs:(nullable NSArray<NSURL *> *)urls {
|
||||||
[self prefetchURLs:urls progress:nil completed:nil];
|
[self prefetchURLs:urls progress:nil completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock {
|
- (void)prefetchURLs:(nullable NSArray<NSURL *> *)urls
|
||||||
|
progress:(nullable SDWebImagePrefetcherProgressBlock)progressBlock
|
||||||
|
completed:(nullable SDWebImagePrefetcherCompletionBlock)completionBlock {
|
||||||
[self cancelPrefetching]; // Prevent duplicate prefetch request
|
[self cancelPrefetching]; // Prevent duplicate prefetch request
|
||||||
self.startedTime = CFAbsoluteTimeGetCurrent();
|
self.startedTime = CFAbsoluteTimeGetCurrent();
|
||||||
self.prefetchURLs = urls;
|
self.prefetchURLs = urls;
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,14 @@
|
||||||
/**
|
/**
|
||||||
* Get the current image URL.
|
* Get the current image URL.
|
||||||
*/
|
*/
|
||||||
- (NSURL *)sd_currentImageURL;
|
- (nullable NSURL *)sd_currentImageURL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the image URL for a control state.
|
* Get the image URL for a control state.
|
||||||
*
|
*
|
||||||
* @param state Which state you want to know the URL for. The values are described in UIControlState.
|
* @param state Which state you want to know the URL for. The values are described in UIControlState.
|
||||||
*/
|
*/
|
||||||
- (NSURL *)sd_imageURLForState:(UIControlState)state;
|
- (nullable NSURL *)sd_imageURLForState:(UIControlState)state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`.
|
* Set the imageView `image` with an `url`.
|
||||||
|
|
@ -34,7 +34,8 @@
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
forState:(UIControlState)state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url` and a placeholder.
|
* Set the imageView `image` with an `url` and a placeholder.
|
||||||
|
|
@ -46,7 +47,9 @@
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @see sd_setImageWithURL:placeholderImage:options:
|
* @see sd_setImageWithURL:placeholderImage:options:
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
forState:(UIControlState)state
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||||
|
|
@ -58,7 +61,10 @@
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
forState:(UIControlState)state
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`.
|
* Set the imageView `image` with an `url`.
|
||||||
|
|
@ -73,7 +79,9 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
forState:(UIControlState)state
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder.
|
* Set the imageView `image` with an `url`, placeholder.
|
||||||
|
|
@ -89,7 +97,10 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
forState:(UIControlState)state
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||||
|
|
@ -106,7 +117,11 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
forState:(UIControlState)state
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the backgroundImageView `image` with an `url`.
|
* Set the backgroundImageView `image` with an `url`.
|
||||||
|
|
@ -116,7 +131,8 @@
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param state The state that uses the specified title. The values are described in UIControlState.
|
* @param state The state that uses the specified title. The values are described in UIControlState.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state;
|
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
|
||||||
|
forState:(UIControlState)state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the backgroundImageView `image` with an `url` and a placeholder.
|
* Set the backgroundImageView `image` with an `url` and a placeholder.
|
||||||
|
|
@ -128,7 +144,9 @@
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @see sd_setImageWithURL:placeholderImage:options:
|
* @see sd_setImageWithURL:placeholderImage:options:
|
||||||
*/
|
*/
|
||||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder;
|
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
|
||||||
|
forState:(UIControlState)state
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the backgroundImageView `image` with an `url`, placeholder and custom options.
|
* Set the backgroundImageView `image` with an `url`, placeholder and custom options.
|
||||||
|
|
@ -140,7 +158,10 @@
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
|
||||||
|
forState:(UIControlState)state
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the backgroundImageView `image` with an `url`.
|
* Set the backgroundImageView `image` with an `url`.
|
||||||
|
|
@ -155,7 +176,9 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
|
||||||
|
forState:(UIControlState)state
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the backgroundImageView `image` with an `url`, placeholder.
|
* Set the backgroundImageView `image` with an `url`, placeholder.
|
||||||
|
|
@ -171,7 +194,10 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
|
||||||
|
forState:(UIControlState)state
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the backgroundImageView `image` with an `url`, placeholder and custom options.
|
* Set the backgroundImageView `image` with an `url`, placeholder and custom options.
|
||||||
|
|
@ -187,7 +213,11 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
|
||||||
|
forState:(UIControlState)state
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel the current image download
|
* Cancel the current image download
|
||||||
|
|
@ -200,30 +230,3 @@
|
||||||
- (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state;
|
- (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@interface UIButton (WebCacheDeprecated)
|
|
||||||
|
|
||||||
- (NSURL *)currentImageURL __deprecated_msg("Use `sd_currentImageURL`");
|
|
||||||
- (NSURL *)imageURLForState:(UIControlState)state __deprecated_msg("Use `sd_imageURLForState:`");
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:`");
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:`");
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:`");
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:completed:`");
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:completed:`");
|
|
||||||
- (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:`");
|
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:`");
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:`");
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:`");
|
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:completed:`");
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:completed:`");
|
|
||||||
- (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:`");
|
|
||||||
|
|
||||||
- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelImageLoadForState:`");
|
|
||||||
- (void)cancelBackgroundImageLoadForState:(UIControlState)state __deprecated_msg("Use `sd_cancelBackgroundImageLoadForState:`");
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,11 @@
|
||||||
|
|
||||||
static char imageURLStorageKey;
|
static char imageURLStorageKey;
|
||||||
|
|
||||||
|
typedef NSMutableDictionary<NSNumber *, NSURL *> SDStateImageURLDictionary;
|
||||||
|
|
||||||
@implementation UIButton (WebCache)
|
@implementation UIButton (WebCache)
|
||||||
|
|
||||||
- (NSURL *)sd_currentImageURL {
|
- (nullable NSURL *)sd_currentImageURL {
|
||||||
NSURL *url = self.imageURLStorage[@(self.state)];
|
NSURL *url = self.imageURLStorage[@(self.state)];
|
||||||
|
|
||||||
if (!url) {
|
if (!url) {
|
||||||
|
|
@ -24,32 +26,35 @@ static char imageURLStorageKey;
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURL *)sd_imageURLForState:(UIControlState)state {
|
- (nullable NSURL *)sd_imageURLForState:(UIControlState)state {
|
||||||
return self.imageURLStorage[@(state)];
|
return self.imageURLStorage[@(state)];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url forState:(UIControlState)state {
|
||||||
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url forState:(UIControlState)state placeholderImage:(nullable UIImage *)placeholder {
|
||||||
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url forState:(UIControlState)state placeholderImage:(nullable UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url forState:(UIControlState)state completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
|
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url forState:(UIControlState)state placeholderImage:(nullable UIImage *)placeholder completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
|
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
forState:(UIControlState)state
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self setImage:placeholder forState:state];
|
[self setImage:placeholder forState:state];
|
||||||
[self sd_cancelImageLoadForState:state];
|
[self sd_cancelImageLoadForState:state];
|
||||||
|
|
||||||
|
|
@ -69,7 +74,7 @@ static char imageURLStorageKey;
|
||||||
self.imageURLStorage[@(state)] = url;
|
self.imageURLStorage[@(state)] = url;
|
||||||
|
|
||||||
__weak __typeof(self)wself = self;
|
__weak __typeof(self)wself = self;
|
||||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
if (!wself) return;
|
if (!wself) return;
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
__strong UIButton *sself = wself;
|
__strong UIButton *sself = wself;
|
||||||
|
|
@ -90,34 +95,38 @@ static char imageURLStorageKey;
|
||||||
[self sd_setImageLoadOperation:operation forState:state];
|
[self sd_setImageLoadOperation:operation forState:state];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url forState:(UIControlState)state {
|
||||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url forState:(UIControlState)state placeholderImage:(nullable UIImage *)placeholder {
|
||||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url forState:(UIControlState)state placeholderImage:(nullable UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url forState:(UIControlState)state completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url forState:(UIControlState)state placeholderImage:(nullable UIImage *)placeholder completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
|
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
|
||||||
|
forState:(UIControlState)state
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self sd_cancelBackgroundImageLoadForState:state];
|
[self sd_cancelBackgroundImageLoadForState:state];
|
||||||
|
|
||||||
[self setBackgroundImage:placeholder forState:state];
|
[self setBackgroundImage:placeholder forState:state];
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
__weak __typeof(self)wself = self;
|
__weak __typeof(self)wself = self;
|
||||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
if (!wself) return;
|
if (!wself) return;
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
__strong UIButton *sself = wself;
|
__strong UIButton *sself = wself;
|
||||||
|
|
@ -162,8 +171,8 @@ static char imageURLStorageKey;
|
||||||
[self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]];
|
[self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSMutableDictionary *)imageURLStorage {
|
- (SDStateImageURLDictionary *)imageURLStorage {
|
||||||
NSMutableDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey);
|
SDStateImageURLDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey);
|
||||||
if (!storage)
|
if (!storage)
|
||||||
{
|
{
|
||||||
storage = [NSMutableDictionary dictionary];
|
storage = [NSMutableDictionary dictionary];
|
||||||
|
|
@ -174,97 +183,3 @@ static char imageURLStorageKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation UIButton (WebCacheDeprecated)
|
|
||||||
|
|
||||||
- (NSURL *)currentImageURL {
|
|
||||||
return [self sd_currentImageURL];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSURL *)imageURLForState:(UIControlState)state {
|
|
||||||
return [self sd_imageURLForState:state];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
|
||||||
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
|
||||||
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
|
||||||
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
|
|
||||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
|
|
||||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
|
||||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)cancelCurrentImageLoad {
|
|
||||||
// in a backwards compatible manner, cancel for current state
|
|
||||||
[self sd_cancelImageLoadForState:self.state];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)cancelBackgroundImageLoadForState:(UIControlState)state {
|
|
||||||
[self sd_cancelBackgroundImageLoadForState:state];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,24 @@
|
||||||
//
|
/*
|
||||||
// UIImage+GIF.h
|
* This file is part of the SDWebImage package.
|
||||||
// LBGIFImage
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
* (c) Laurin Brandner
|
||||||
// Created by Laurin Brandner on 06.01.12.
|
*
|
||||||
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
//
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
@interface UIImage (GIF)
|
@interface UIImage (GIF)
|
||||||
|
|
||||||
+ (UIImage *)sd_animatedGIFNamed:(NSString *)name;
|
/**
|
||||||
|
* Compatibility method - creates an animated UIImage from an NSData, it will only contain the 1st frame image
|
||||||
|
*/
|
||||||
+ (UIImage *)sd_animatedGIFWithData:(NSData *)data;
|
+ (UIImage *)sd_animatedGIFWithData:(NSData *)data;
|
||||||
|
|
||||||
- (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size;
|
/**
|
||||||
|
* Checks if an UIImage instance is a GIF. Will use the `images` array
|
||||||
|
*/
|
||||||
|
- (BOOL)isGIF;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
//
|
/*
|
||||||
// UIImage+GIF.m
|
* This file is part of the SDWebImage package.
|
||||||
// LBGIFImage
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
* (c) Laurin Brandner
|
||||||
// Created by Laurin Brandner on 06.01.12.
|
*
|
||||||
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
//
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
#import "UIImage+GIF.h"
|
#import "UIImage+GIF.h"
|
||||||
#import <ImageIO/ImageIO.h>
|
#import <ImageIO/ImageIO.h>
|
||||||
|
#import "objc/runtime.h"
|
||||||
|
|
||||||
@implementation UIImage (GIF)
|
@implementation UIImage (GIF)
|
||||||
|
|
||||||
|
|
@ -20,142 +22,26 @@
|
||||||
|
|
||||||
size_t count = CGImageSourceGetCount(source);
|
size_t count = CGImageSourceGetCount(source);
|
||||||
|
|
||||||
UIImage *animatedImage;
|
UIImage *staticImage;
|
||||||
|
|
||||||
if (count <= 1) {
|
if (count <= 1) {
|
||||||
animatedImage = [[UIImage alloc] initWithData:data];
|
staticImage = [[UIImage alloc] initWithData:data];
|
||||||
}
|
} else {
|
||||||
else {
|
// we will only retrieve the 1st frame. the full GIF support is available via the FLAnimatedImageView category.
|
||||||
NSMutableArray *images = [NSMutableArray array];
|
// this here is only code to allow drawing animated images as static ones
|
||||||
|
CGImageRef CGImage = CGImageSourceCreateImageAtIndex(source, 0, NULL);
|
||||||
NSTimeInterval duration = 0.0f;
|
UIImage *frameImage = [UIImage imageWithCGImage:CGImage scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp];
|
||||||
|
staticImage = [UIImage animatedImageWithImages:@[frameImage] duration:0.0f];
|
||||||
for (size_t i = 0; i < count; i++) {
|
CGImageRelease(CGImage);
|
||||||
CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL);
|
|
||||||
if (!image) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
duration += [self sd_frameDurationAtIndex:i source:source];
|
|
||||||
|
|
||||||
[images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]];
|
|
||||||
|
|
||||||
CGImageRelease(image);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!duration) {
|
|
||||||
duration = (1.0f / 10.0f) * count;
|
|
||||||
}
|
|
||||||
|
|
||||||
animatedImage = [UIImage animatedImageWithImages:images duration:duration];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(source);
|
CFRelease(source);
|
||||||
|
|
||||||
return animatedImage;
|
return staticImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (float)sd_frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source {
|
- (BOOL)isGIF {
|
||||||
float frameDuration = 0.1f;
|
return (self.images != nil);
|
||||||
CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil);
|
|
||||||
NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties;
|
|
||||||
NSDictionary *gifProperties = frameProperties[(NSString *)kCGImagePropertyGIFDictionary];
|
|
||||||
|
|
||||||
NSNumber *delayTimeUnclampedProp = gifProperties[(NSString *)kCGImagePropertyGIFUnclampedDelayTime];
|
|
||||||
if (delayTimeUnclampedProp) {
|
|
||||||
frameDuration = [delayTimeUnclampedProp floatValue];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
NSNumber *delayTimeProp = gifProperties[(NSString *)kCGImagePropertyGIFDelayTime];
|
|
||||||
if (delayTimeProp) {
|
|
||||||
frameDuration = [delayTimeProp floatValue];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Many annoying ads specify a 0 duration to make an image flash as quickly as possible.
|
|
||||||
// We follow Firefox's behavior and use a duration of 100 ms for any frames that specify
|
|
||||||
// a duration of <= 10 ms. See <rdar://problem/7689300> and <http://webkit.org/b/36082>
|
|
||||||
// for more information.
|
|
||||||
|
|
||||||
if (frameDuration < 0.011f) {
|
|
||||||
frameDuration = 0.100f;
|
|
||||||
}
|
|
||||||
|
|
||||||
CFRelease(cfFrameProperties);
|
|
||||||
return frameDuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (UIImage *)sd_animatedGIFNamed:(NSString *)name {
|
|
||||||
CGFloat scale = [UIScreen mainScreen].scale;
|
|
||||||
|
|
||||||
if (scale > 1.0f) {
|
|
||||||
NSString *retinaPath = [[NSBundle mainBundle] pathForResource:[name stringByAppendingString:@"@2x"] ofType:@"gif"];
|
|
||||||
|
|
||||||
NSData *data = [NSData dataWithContentsOfFile:retinaPath];
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
return [UIImage sd_animatedGIFWithData:data];
|
|
||||||
}
|
|
||||||
|
|
||||||
NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"];
|
|
||||||
|
|
||||||
data = [NSData dataWithContentsOfFile:path];
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
return [UIImage sd_animatedGIFWithData:data];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [UIImage imageNamed:name];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"];
|
|
||||||
|
|
||||||
NSData *data = [NSData dataWithContentsOfFile:path];
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
return [UIImage sd_animatedGIFWithData:data];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [UIImage imageNamed:name];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size {
|
|
||||||
if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero)) {
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
CGSize scaledSize = size;
|
|
||||||
CGPoint thumbnailPoint = CGPointZero;
|
|
||||||
|
|
||||||
CGFloat widthFactor = size.width / self.size.width;
|
|
||||||
CGFloat heightFactor = size.height / self.size.height;
|
|
||||||
CGFloat scaleFactor = (widthFactor > heightFactor) ? widthFactor : heightFactor;
|
|
||||||
scaledSize.width = self.size.width * scaleFactor;
|
|
||||||
scaledSize.height = self.size.height * scaleFactor;
|
|
||||||
|
|
||||||
if (widthFactor > heightFactor) {
|
|
||||||
thumbnailPoint.y = (size.height - scaledSize.height) * 0.5;
|
|
||||||
}
|
|
||||||
else if (widthFactor < heightFactor) {
|
|
||||||
thumbnailPoint.x = (size.width - scaledSize.width) * 0.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSMutableArray *scaledImages = [NSMutableArray array];
|
|
||||||
|
|
||||||
for (UIImage *image in self.images) {
|
|
||||||
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
|
|
||||||
|
|
||||||
[image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)];
|
|
||||||
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
||||||
|
|
||||||
[scaledImages addObject:newImage];
|
|
||||||
|
|
||||||
UIGraphicsEndImageContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
return [UIImage animatedImageWithImages:scaledImages duration:self.duration];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
//
|
/*
|
||||||
// UIImage+MultiFormat.h
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Olivier Poitrey on 07/06/13.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
// Copyright (c) 2013 Dailymotion. All rights reserved.
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
@interface UIImage (MultiFormat)
|
@interface UIImage (MultiFormat)
|
||||||
|
|
||||||
+ (UIImage *)sd_imageWithData:(NSData *)data;
|
+ (nullable UIImage *)sd_imageWithData:(nullable NSData *)data;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
//
|
/*
|
||||||
// UIImage+MultiFormat.m
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Olivier Poitrey on 07/06/13.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
// Copyright (c) 2013 Dailymotion. All rights reserved.
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#import "UIImage+MultiFormat.h"
|
#import "UIImage+MultiFormat.h"
|
||||||
#import "UIImage+GIF.h"
|
#import "UIImage+GIF.h"
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
@implementation UIImage (MultiFormat)
|
@implementation UIImage (MultiFormat)
|
||||||
|
|
||||||
+ (UIImage *)sd_imageWithData:(NSData *)data {
|
+ (nullable UIImage *)sd_imageWithData:(nullable NSData *)data {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +48,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
+(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData {
|
+(UIImageOrientation)sd_imageOrientationFromImageData:(nonnull NSData *)imageData {
|
||||||
UIImageOrientation result = UIImageOrientationUp;
|
UIImageOrientation result = UIImageOrientationUp;
|
||||||
CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);
|
CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);
|
||||||
if (imageSource) {
|
if (imageSource) {
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,18 @@
|
||||||
//
|
/*
|
||||||
// UIImage+WebP.h
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Olivier Poitrey on 07/06/13.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
// Copyright (c) 2013 Dailymotion. All rights reserved.
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#ifdef SD_WEBP
|
#ifdef SD_WEBP
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
// Fix for issue #416 Undefined symbols for architecture armv7 since WebP introduction when deploying to device
|
|
||||||
void WebPInitPremultiplyNEON(void);
|
|
||||||
|
|
||||||
void WebPInitUpsamplersNEON(void);
|
|
||||||
|
|
||||||
void VP8DspInitNEON(void);
|
|
||||||
|
|
||||||
@interface UIImage (WebP)
|
@interface UIImage (WebP)
|
||||||
|
|
||||||
+ (UIImage *)sd_imageWithWebPData:(NSData *)data;
|
+ (nullable UIImage *)sd_imageWithWebPData:(nullable NSData *)data;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
//
|
/*
|
||||||
// UIImage+WebP.m
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Olivier Poitrey on 07/06/13.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
// Copyright (c) 2013 Dailymotion. All rights reserved.
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#ifdef SD_WEBP
|
#ifdef SD_WEBP
|
||||||
#import "UIImage+WebP.h"
|
#import "UIImage+WebP.h"
|
||||||
|
|
@ -16,14 +16,13 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Callback for CGDataProviderRelease
|
// Callback for CGDataProviderRelease
|
||||||
static void FreeImageData(void *info, const void *data, size_t size)
|
static void FreeImageData(void *info, const void *data, size_t size) {
|
||||||
{
|
|
||||||
free((void *)data);
|
free((void *)data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@implementation UIImage (WebP)
|
@implementation UIImage (WebP)
|
||||||
|
|
||||||
+ (UIImage *)sd_imageWithWebPData:(NSData *)data {
|
+ (nullable UIImage *)sd_imageWithWebPData:(nullable NSData *)data {
|
||||||
WebPDecoderConfig config;
|
WebPDecoderConfig config;
|
||||||
if (!WebPInitDecoderConfig(&config)) {
|
if (!WebPInitDecoderConfig(&config)) {
|
||||||
return nil;
|
return nil;
|
||||||
|
|
@ -68,11 +67,4 @@ static void FreeImageData(void *info, const void *data, size_t size)
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#if !COCOAPODS
|
|
||||||
// Functions to resolve some undefined symbols when using WebP and force_load flag
|
|
||||||
void WebPInitPremultiplyNEON(void) {}
|
|
||||||
void WebPInitUpsamplersNEON(void) {}
|
|
||||||
void VP8DspInitNEON(void) {}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url;
|
- (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `highlightedImage` with an `url` and custom options.
|
* Set the imageView `highlightedImage` with an `url` and custom options.
|
||||||
|
|
@ -32,7 +32,8 @@
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options;
|
- (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url
|
||||||
|
options:(SDWebImageOptions)options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `highlightedImage` with an `url`.
|
* Set the imageView `highlightedImage` with an `url`.
|
||||||
|
|
@ -46,7 +47,8 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `highlightedImage` with an `url` and custom options.
|
* Set the imageView `highlightedImage` with an `url` and custom options.
|
||||||
|
|
@ -61,7 +63,9 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `highlightedImage` with an `url` and custom options.
|
* Set the imageView `highlightedImage` with an `url` and custom options.
|
||||||
|
|
@ -77,7 +81,10 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel the current download
|
* Cancel the current download
|
||||||
|
|
@ -85,16 +92,3 @@
|
||||||
- (void)sd_cancelCurrentHighlightedImageLoad;
|
- (void)sd_cancelCurrentHighlightedImageLoad;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@interface UIImageView (HighlightedWebCacheDeprecated)
|
|
||||||
|
|
||||||
- (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:`");
|
|
||||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:`");
|
|
||||||
- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:completed:`");
|
|
||||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:completed:`");
|
|
||||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:progress:completed:`");
|
|
||||||
|
|
||||||
- (void)cancelCurrentHighlightedImageLoad __deprecated_msg("Use `sd_cancelCurrentHighlightedImageLoad`");
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
||||||
|
|
@ -13,45 +13,47 @@
|
||||||
|
|
||||||
@implementation UIImageView (HighlightedWebCache)
|
@implementation UIImageView (HighlightedWebCache)
|
||||||
|
|
||||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url {
|
- (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url {
|
||||||
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
|
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
|
- (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url options:(SDWebImageOptions)options {
|
||||||
[self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
|
[self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock];
|
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url options:(SDWebImageOptions)options completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self sd_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock];
|
[self sd_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setHighlightedImageWithURL:(nullable NSURL *)url
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self sd_cancelCurrentHighlightedImageLoad];
|
[self sd_cancelCurrentHighlightedImageLoad];
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
__weak __typeof(self)wself = self;
|
__weak __typeof(self)wself = self;
|
||||||
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
id<SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
if (!wself) return;
|
if (!wself) return;
|
||||||
dispatch_main_sync_safe (^
|
dispatch_main_sync_safe (^{
|
||||||
{
|
if (!wself) return;
|
||||||
if (!wself) return;
|
if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock)
|
||||||
if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock)
|
{
|
||||||
{
|
completedBlock(image, error, cacheType, url);
|
||||||
completedBlock(image, error, cacheType, url);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
else if (image) {
|
||||||
else if (image) {
|
wself.highlightedImage = image;
|
||||||
wself.highlightedImage = image;
|
[wself setNeedsLayout];
|
||||||
[wself setNeedsLayout];
|
}
|
||||||
}
|
if (completedBlock && finished) {
|
||||||
if (completedBlock && finished) {
|
completedBlock(image, error, cacheType, url);
|
||||||
completedBlock(image, error, cacheType, url);
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}];
|
}];
|
||||||
[self sd_setImageLoadOperation:operation forKey:UIImageViewHighlightedWebCacheOperationKey];
|
[self sd_setImageLoadOperation:operation forKey:UIImageViewHighlightedWebCacheOperationKey];
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -69,44 +71,3 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation UIImageView (HighlightedWebCacheDeprecated)
|
|
||||||
|
|
||||||
- (void)setHighlightedImageWithURL:(NSURL *)url {
|
|
||||||
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
|
|
||||||
[self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)cancelCurrentHighlightedImageLoad {
|
|
||||||
[self sd_cancelCurrentHighlightedImageLoad];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,9 @@
|
||||||
* Get the current image URL.
|
* Get the current image URL.
|
||||||
*
|
*
|
||||||
* Note that because of the limitations of categories this property can get out of sync
|
* Note that because of the limitations of categories this property can get out of sync
|
||||||
* if you use sd_setImage: directly.
|
* if you use setImage: directly.
|
||||||
*/
|
*/
|
||||||
- (NSURL *)sd_imageURL;
|
- (nullable NSURL *)sd_imageURL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`.
|
* Set the imageView `image` with an `url`.
|
||||||
|
|
@ -59,7 +59,7 @@
|
||||||
*
|
*
|
||||||
* @param url The url for the image.
|
* @param url The url for the image.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url` and a placeholder.
|
* Set the imageView `image` with an `url` and a placeholder.
|
||||||
|
|
@ -70,7 +70,8 @@
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @see sd_setImageWithURL:placeholderImage:options:
|
* @see sd_setImageWithURL:placeholderImage:options:
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||||
|
|
@ -81,7 +82,9 @@
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`.
|
* Set the imageView `image` with an `url`.
|
||||||
|
|
@ -95,7 +98,8 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder.
|
* Set the imageView `image` with an `url`, placeholder.
|
||||||
|
|
@ -110,7 +114,9 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||||
|
|
@ -126,7 +132,10 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* Set the imageView `image` with an `url`, placeholder and custom options.
|
||||||
|
|
@ -143,7 +152,11 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url` and optionally a placeholder image.
|
* Set the imageView `image` with an `url` and optionally a placeholder image.
|
||||||
|
|
@ -160,14 +173,18 @@
|
||||||
* indicating if the image was retrieved from the local cache or from the network.
|
* indicating if the image was retrieved from the local cache or from the network.
|
||||||
* The fourth parameter is the original image url.
|
* The fourth parameter is the original image url.
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
|
- (void)sd_setImageWithPreviousCachedImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download an array of images and starts them in an animation loop
|
* Download an array of images and starts them in an animation loop
|
||||||
*
|
*
|
||||||
* @param arrayOfURLs An array of NSURL
|
* @param arrayOfURLs An array of NSURL
|
||||||
*/
|
*/
|
||||||
- (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs;
|
- (void)sd_setAnimationImagesWithURLs:(nonnull NSArray<NSURL *> *)arrayOfURLs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel the current download
|
* Cancel the current download
|
||||||
|
|
@ -188,28 +205,9 @@
|
||||||
*/
|
*/
|
||||||
- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style;
|
- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style;
|
||||||
|
|
||||||
@end
|
- (BOOL)showActivityIndicatorView;
|
||||||
|
- (void)addActivityIndicator;
|
||||||
|
- (void)removeActivityIndicator;
|
||||||
|
|
||||||
|
|
||||||
@interface UIImageView (WebCacheDeprecated)
|
|
||||||
|
|
||||||
- (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`");
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`");
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`");
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options`");
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`");
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`");
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`");
|
|
||||||
- (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:`");
|
|
||||||
|
|
||||||
- (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:`");
|
|
||||||
|
|
||||||
- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs __deprecated_msg("Use `sd_setAnimationImagesWithURLs:`");
|
|
||||||
|
|
||||||
- (void)cancelCurrentArrayLoad __deprecated_msg("Use `sd_cancelCurrentAnimationImagesLoad`");
|
|
||||||
|
|
||||||
- (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`");
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -17,31 +17,35 @@ static char TAG_ACTIVITY_SHOW;
|
||||||
|
|
||||||
@implementation UIImageView (WebCache)
|
@implementation UIImageView (WebCache)
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url {
|
||||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder {
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(SDWebImageOptions)options {
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock];
|
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock];
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(SDWebImageOptions)options completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock];
|
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
[self sd_cancelCurrentImageLoad];
|
[self sd_cancelCurrentImageLoad];
|
||||||
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
|
|
||||||
|
|
@ -59,7 +63,7 @@ static char TAG_ACTIVITY_SHOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
__weak __typeof(self)wself = self;
|
__weak __typeof(self)wself = self;
|
||||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
[wself removeActivityIndicator];
|
[wself removeActivityIndicator];
|
||||||
if (!wself) return;
|
if (!wself) return;
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
|
|
@ -95,31 +99,35 @@ static char TAG_ACTIVITY_SHOW;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
|
- (void)sd_setImageWithPreviousCachedImageWithURL:(nullable NSURL *)url
|
||||||
|
placeholderImage:(nullable UIImage *)placeholder
|
||||||
|
options:(SDWebImageOptions)options
|
||||||
|
progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||||
|
completed:(nullable SDExternalCompletionBlock)completedBlock {
|
||||||
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url];
|
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url];
|
||||||
UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
|
UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
|
||||||
|
|
||||||
[self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock];
|
[self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURL *)sd_imageURL {
|
- (nullable NSURL *)sd_imageURL {
|
||||||
return objc_getAssociatedObject(self, &imageURLKey);
|
return objc_getAssociatedObject(self, &imageURLKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs {
|
- (void)sd_setAnimationImagesWithURLs:(nonnull NSArray<NSURL *> *)arrayOfURLs {
|
||||||
[self sd_cancelCurrentAnimationImagesLoad];
|
[self sd_cancelCurrentAnimationImagesLoad];
|
||||||
__weak __typeof(self)wself = self;
|
__weak __typeof(self)wself = self;
|
||||||
|
|
||||||
NSMutableArray *operationsArray = [[NSMutableArray alloc] init];
|
NSMutableArray<id<SDWebImageOperation>> *operationsArray = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
for (NSURL *logoImageURL in arrayOfURLs) {
|
for (NSURL *logoImageURL in arrayOfURLs) {
|
||||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager loadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
if (!wself) return;
|
if (!wself) return;
|
||||||
dispatch_main_sync_safe(^{
|
dispatch_main_sync_safe(^{
|
||||||
__strong UIImageView *sself = wself;
|
__strong UIImageView *sself = wself;
|
||||||
[sself stopAnimating];
|
[sself stopAnimating];
|
||||||
if (sself && image) {
|
if (sself && image) {
|
||||||
NSMutableArray *currentImages = [[sself animationImages] mutableCopy];
|
NSMutableArray<UIImage *> *currentImages = [[sself animationImages] mutableCopy];
|
||||||
if (!currentImages) {
|
if (!currentImages) {
|
||||||
currentImages = [[NSMutableArray alloc] init];
|
currentImages = [[NSMutableArray alloc] init];
|
||||||
}
|
}
|
||||||
|
|
@ -134,7 +142,7 @@ static char TAG_ACTIVITY_SHOW;
|
||||||
[operationsArray addObject:operation];
|
[operationsArray addObject:operation];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self sd_setImageLoadOperation:[NSArray arrayWithArray:operationsArray] forKey:@"UIImageViewAnimationImages"];
|
[self sd_setImageLoadOperation:[operationsArray copy] forKey:@"UIImageViewAnimationImages"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_cancelCurrentImageLoad {
|
- (void)sd_cancelCurrentImageLoad {
|
||||||
|
|
@ -155,11 +163,11 @@ static char TAG_ACTIVITY_SHOW;
|
||||||
objc_setAssociatedObject(self, &TAG_ACTIVITY_INDICATOR, activityIndicator, OBJC_ASSOCIATION_RETAIN);
|
objc_setAssociatedObject(self, &TAG_ACTIVITY_INDICATOR, activityIndicator, OBJC_ASSOCIATION_RETAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setShowActivityIndicatorView:(BOOL)show{
|
- (void)setShowActivityIndicatorView:(BOOL)show {
|
||||||
objc_setAssociatedObject(self, &TAG_ACTIVITY_SHOW, [NSNumber numberWithBool:show], OBJC_ASSOCIATION_RETAIN);
|
objc_setAssociatedObject(self, &TAG_ACTIVITY_SHOW, @(show), OBJC_ASSOCIATION_RETAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)showActivityIndicatorView{
|
- (BOOL)showActivityIndicatorView {
|
||||||
return [objc_getAssociatedObject(self, &TAG_ACTIVITY_SHOW) boolValue];
|
return [objc_getAssociatedObject(self, &TAG_ACTIVITY_SHOW) boolValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,72 +218,3 @@ static char TAG_ACTIVITY_SHOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation UIImageView (WebCacheDeprecated)
|
|
||||||
|
|
||||||
- (NSURL *)imageURL {
|
|
||||||
return [self sd_imageURL];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url {
|
|
||||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
|
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
|
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
|
|
||||||
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
|
||||||
if (completedBlock) {
|
|
||||||
completedBlock(image, error, cacheType);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
|
|
||||||
[self sd_setImageWithPreviousCachedImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:completedBlock];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)cancelCurrentArrayLoad {
|
|
||||||
[self sd_cancelCurrentAnimationImagesLoad];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)cancelCurrentImageLoad {
|
|
||||||
[self sd_cancelCurrentImageLoad];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs {
|
|
||||||
[self sd_setAnimationImagesWithURLs:arrayOfURLs];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
||||||
|
|
@ -17,20 +17,20 @@
|
||||||
* @param operation the operation
|
* @param operation the operation
|
||||||
* @param key key for storing the operation
|
* @param key key for storing the operation
|
||||||
*/
|
*/
|
||||||
- (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key;
|
- (void)sd_setImageLoadOperation:(nullable id)operation forKey:(nullable NSString *)key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel all operations for the current UIView and key
|
* Cancel all operations for the current UIView and key
|
||||||
*
|
*
|
||||||
* @param key key for identifying the operations
|
* @param key key for identifying the operations
|
||||||
*/
|
*/
|
||||||
- (void)sd_cancelImageLoadOperationWithKey:(NSString *)key;
|
- (void)sd_cancelImageLoadOperationWithKey:(nullable NSString *)key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Just remove the operations corresponding to the current UIView and key without cancelling them
|
* Just remove the operations corresponding to the current UIView and key without cancelling them
|
||||||
*
|
*
|
||||||
* @param key key for identifying the operations
|
* @param key key for identifying the operations
|
||||||
*/
|
*/
|
||||||
- (void)sd_removeImageLoadOperationWithKey:(NSString *)key;
|
- (void)sd_removeImageLoadOperationWithKey:(nullable NSString *)key;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,12 @@
|
||||||
|
|
||||||
static char loadOperationKey;
|
static char loadOperationKey;
|
||||||
|
|
||||||
|
typedef NSMutableDictionary<NSString *, id> SDOperationsDictionary;
|
||||||
|
|
||||||
@implementation UIView (WebCacheOperation)
|
@implementation UIView (WebCacheOperation)
|
||||||
|
|
||||||
- (NSMutableDictionary *)operationDictionary {
|
- (SDOperationsDictionary *)operationDictionary {
|
||||||
NSMutableDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey);
|
SDOperationsDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey);
|
||||||
if (operations) {
|
if (operations) {
|
||||||
return operations;
|
return operations;
|
||||||
}
|
}
|
||||||
|
|
@ -23,16 +25,18 @@ static char loadOperationKey;
|
||||||
return operations;
|
return operations;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key {
|
- (void)sd_setImageLoadOperation:(nullable id)operation forKey:(nullable NSString *)key {
|
||||||
[self sd_cancelImageLoadOperationWithKey:key];
|
if (key) {
|
||||||
NSMutableDictionary *operationDictionary = [self operationDictionary];
|
[self sd_cancelImageLoadOperationWithKey:key];
|
||||||
[operationDictionary setObject:operation forKey:key];
|
SDOperationsDictionary *operationDictionary = [self operationDictionary];
|
||||||
|
operationDictionary[key] = operation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_cancelImageLoadOperationWithKey:(NSString *)key {
|
- (void)sd_cancelImageLoadOperationWithKey:(nullable NSString *)key {
|
||||||
// Cancel in progress downloader from queue
|
// Cancel in progress downloader from queue
|
||||||
NSMutableDictionary *operationDictionary = [self operationDictionary];
|
SDOperationsDictionary *operationDictionary = [self operationDictionary];
|
||||||
id operations = [operationDictionary objectForKey:key];
|
id operations = operationDictionary[key];
|
||||||
if (operations) {
|
if (operations) {
|
||||||
if ([operations isKindOfClass:[NSArray class]]) {
|
if ([operations isKindOfClass:[NSArray class]]) {
|
||||||
for (id <SDWebImageOperation> operation in operations) {
|
for (id <SDWebImageOperation> operation in operations) {
|
||||||
|
|
@ -47,9 +51,11 @@ static char loadOperationKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sd_removeImageLoadOperationWithKey:(NSString *)key {
|
- (void)sd_removeImageLoadOperationWithKey:(nullable NSString *)key {
|
||||||
NSMutableDictionary *operationDictionary = [self operationDictionary];
|
if (key) {
|
||||||
[operationDictionary removeObjectForKey:key];
|
SDOperationsDictionary *operationDictionary = [self operationDictionary];
|
||||||
|
[operationDictionary removeObjectForKey:key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@
|
||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
2278D185E97AF851CF3F9A07 /* libPods-Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F0EF05B6C461610578D6C2A6 /* libPods-Tests.a */; };
|
0D87E1F83BD319CEC7622E9F /* libPods-Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0462A7F023A057322E59B3C5 /* libPods-Tests.a */; };
|
||||||
|
1E3C51E919B46E370092B5E6 /* SDWebImageDownloaderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E3C51E819B46E370092B5E6 /* SDWebImageDownloaderTests.m */; };
|
||||||
5F7F38AD1AE2A77A00B0E330 /* TestImage.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */; };
|
5F7F38AD1AE2A77A00B0E330 /* TestImage.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */; };
|
||||||
DA248D57195472AA00390AB0 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D56195472AA00390AB0 /* XCTest.framework */; };
|
DA248D57195472AA00390AB0 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D56195472AA00390AB0 /* XCTest.framework */; };
|
||||||
DA248D59195472AA00390AB0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D58195472AA00390AB0 /* Foundation.framework */; };
|
DA248D59195472AA00390AB0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA248D58195472AA00390AB0 /* Foundation.framework */; };
|
||||||
|
|
@ -19,9 +20,11 @@
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
0EAE9F732E05E3878DC9D2D1 /* Pods-Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.debug.xcconfig"; sourceTree = "<group>"; };
|
0462A7F023A057322E59B3C5 /* libPods-Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
2FAA0419497C5AA7F0EA0E20 /* Pods-Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.release.xcconfig"; sourceTree = "<group>"; };
|
1E3C51E819B46E370092B5E6 /* SDWebImageDownloaderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageDownloaderTests.m; sourceTree = "<group>"; };
|
||||||
5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = TestImage.jpg; sourceTree = "<group>"; };
|
5F7F38AC1AE2A77A00B0E330 /* TestImage.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = TestImage.jpg; sourceTree = "<group>"; };
|
||||||
|
700B00151041D7EE118B1ABD /* Pods-Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.debug.xcconfig"; sourceTree = "<group>"; };
|
||||||
|
A0085854E7D88C98F2F6C9FC /* Pods-Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.release.xcconfig"; sourceTree = "<group>"; };
|
||||||
DA248D53195472AA00390AB0 /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
DA248D53195472AA00390AB0 /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
DA248D56195472AA00390AB0 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
|
DA248D56195472AA00390AB0 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
|
||||||
DA248D58195472AA00390AB0 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
|
DA248D58195472AA00390AB0 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
|
||||||
|
|
@ -32,7 +35,6 @@
|
||||||
DA248D68195475D800390AB0 /* SDImageCacheTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDImageCacheTests.m; sourceTree = "<group>"; };
|
DA248D68195475D800390AB0 /* SDImageCacheTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDImageCacheTests.m; sourceTree = "<group>"; };
|
||||||
DA248D6A195476AC00390AB0 /* SDWebImageManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageManagerTests.m; sourceTree = "<group>"; };
|
DA248D6A195476AC00390AB0 /* SDWebImageManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageManagerTests.m; sourceTree = "<group>"; };
|
||||||
DA91BEBB19795BC9006F2536 /* UIImageMultiFormatTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIImageMultiFormatTests.m; sourceTree = "<group>"; };
|
DA91BEBB19795BC9006F2536 /* UIImageMultiFormatTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIImageMultiFormatTests.m; sourceTree = "<group>"; };
|
||||||
F0EF05B6C461610578D6C2A6 /* libPods-Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
|
@ -43,18 +45,18 @@
|
||||||
DA248D57195472AA00390AB0 /* XCTest.framework in Frameworks */,
|
DA248D57195472AA00390AB0 /* XCTest.framework in Frameworks */,
|
||||||
DA248D5B195472AA00390AB0 /* UIKit.framework in Frameworks */,
|
DA248D5B195472AA00390AB0 /* UIKit.framework in Frameworks */,
|
||||||
DA248D59195472AA00390AB0 /* Foundation.framework in Frameworks */,
|
DA248D59195472AA00390AB0 /* Foundation.framework in Frameworks */,
|
||||||
2278D185E97AF851CF3F9A07 /* libPods-Tests.a in Frameworks */,
|
0D87E1F83BD319CEC7622E9F /* libPods-Tests.a in Frameworks */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
/* End PBXFrameworksBuildPhase section */
|
/* End PBXFrameworksBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXGroup section */
|
/* Begin PBXGroup section */
|
||||||
8D1A343B1A6D91E95D7795EF /* Pods */ = {
|
3E8D7663CD326C6F44B23889 /* Pods */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
0EAE9F732E05E3878DC9D2D1 /* Pods-Tests.debug.xcconfig */,
|
700B00151041D7EE118B1ABD /* Pods-Tests.debug.xcconfig */,
|
||||||
2FAA0419497C5AA7F0EA0E20 /* Pods-Tests.release.xcconfig */,
|
A0085854E7D88C98F2F6C9FC /* Pods-Tests.release.xcconfig */,
|
||||||
);
|
);
|
||||||
name = Pods;
|
name = Pods;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
|
@ -65,7 +67,7 @@
|
||||||
DA248D5C195472AA00390AB0 /* Tests */,
|
DA248D5C195472AA00390AB0 /* Tests */,
|
||||||
DA248D55195472AA00390AB0 /* Frameworks */,
|
DA248D55195472AA00390AB0 /* Frameworks */,
|
||||||
DA248D54195472AA00390AB0 /* Products */,
|
DA248D54195472AA00390AB0 /* Products */,
|
||||||
8D1A343B1A6D91E95D7795EF /* Pods */,
|
3E8D7663CD326C6F44B23889 /* Pods */,
|
||||||
);
|
);
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
|
@ -83,7 +85,7 @@
|
||||||
DA248D56195472AA00390AB0 /* XCTest.framework */,
|
DA248D56195472AA00390AB0 /* XCTest.framework */,
|
||||||
DA248D58195472AA00390AB0 /* Foundation.framework */,
|
DA248D58195472AA00390AB0 /* Foundation.framework */,
|
||||||
DA248D5A195472AA00390AB0 /* UIKit.framework */,
|
DA248D5A195472AA00390AB0 /* UIKit.framework */,
|
||||||
F0EF05B6C461610578D6C2A6 /* libPods-Tests.a */,
|
0462A7F023A057322E59B3C5 /* libPods-Tests.a */,
|
||||||
);
|
);
|
||||||
name = Frameworks;
|
name = Frameworks;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
|
@ -96,6 +98,7 @@
|
||||||
DA248D68195475D800390AB0 /* SDImageCacheTests.m */,
|
DA248D68195475D800390AB0 /* SDImageCacheTests.m */,
|
||||||
DA248D6A195476AC00390AB0 /* SDWebImageManagerTests.m */,
|
DA248D6A195476AC00390AB0 /* SDWebImageManagerTests.m */,
|
||||||
DA91BEBB19795BC9006F2536 /* UIImageMultiFormatTests.m */,
|
DA91BEBB19795BC9006F2536 /* UIImageMultiFormatTests.m */,
|
||||||
|
1E3C51E819B46E370092B5E6 /* SDWebImageDownloaderTests.m */,
|
||||||
);
|
);
|
||||||
path = Tests;
|
path = Tests;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
|
@ -117,12 +120,12 @@
|
||||||
isa = PBXNativeTarget;
|
isa = PBXNativeTarget;
|
||||||
buildConfigurationList = DA248D67195472AA00390AB0 /* Build configuration list for PBXNativeTarget "Tests" */;
|
buildConfigurationList = DA248D67195472AA00390AB0 /* Build configuration list for PBXNativeTarget "Tests" */;
|
||||||
buildPhases = (
|
buildPhases = (
|
||||||
FBC8982311CD4ED9A3006D45 /* 📦 Check Pods Manifest.lock */,
|
09522B7196293172D6408744 /* 📦 Check Pods Manifest.lock */,
|
||||||
DA248D4F195472AA00390AB0 /* Sources */,
|
DA248D4F195472AA00390AB0 /* Sources */,
|
||||||
DA248D50195472AA00390AB0 /* Frameworks */,
|
DA248D50195472AA00390AB0 /* Frameworks */,
|
||||||
DA248D51195472AA00390AB0 /* Resources */,
|
DA248D51195472AA00390AB0 /* Resources */,
|
||||||
D6347736BDF64FC5A4D078A4 /* 📦 Copy Pods Resources */,
|
C86216497B5A0BA9501E2C07 /* 📦 Embed Pods Frameworks */,
|
||||||
4B51E412BA3594400947AC71 /* 📦 Embed Pods Frameworks */,
|
85E5D3885A03BFC23B050908 /* 📦 Copy Pods Resources */,
|
||||||
);
|
);
|
||||||
buildRules = (
|
buildRules = (
|
||||||
);
|
);
|
||||||
|
|
@ -139,7 +142,7 @@
|
||||||
DA248D461954721A00390AB0 /* Project object */ = {
|
DA248D461954721A00390AB0 /* Project object */ = {
|
||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
attributes = {
|
attributes = {
|
||||||
LastUpgradeCheck = 0510;
|
LastUpgradeCheck = 0730;
|
||||||
};
|
};
|
||||||
buildConfigurationList = DA248D491954721A00390AB0 /* Build configuration list for PBXProject "SDWebImage Tests" */;
|
buildConfigurationList = DA248D491954721A00390AB0 /* Build configuration list for PBXProject "SDWebImage Tests" */;
|
||||||
compatibilityVersion = "Xcode 3.2";
|
compatibilityVersion = "Xcode 3.2";
|
||||||
|
|
@ -171,37 +174,7 @@
|
||||||
/* End PBXResourcesBuildPhase section */
|
/* End PBXResourcesBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXShellScriptBuildPhase section */
|
/* Begin PBXShellScriptBuildPhase section */
|
||||||
4B51E412BA3594400947AC71 /* 📦 Embed Pods Frameworks */ = {
|
09522B7196293172D6408744 /* 📦 Check Pods Manifest.lock */ = {
|
||||||
isa = PBXShellScriptBuildPhase;
|
|
||||||
buildActionMask = 2147483647;
|
|
||||||
files = (
|
|
||||||
);
|
|
||||||
inputPaths = (
|
|
||||||
);
|
|
||||||
name = "📦 Embed Pods Frameworks";
|
|
||||||
outputPaths = (
|
|
||||||
);
|
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
|
||||||
shellPath = /bin/sh;
|
|
||||||
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests/Pods-Tests-frameworks.sh\"\n";
|
|
||||||
showEnvVarsInLog = 0;
|
|
||||||
};
|
|
||||||
D6347736BDF64FC5A4D078A4 /* 📦 Copy Pods Resources */ = {
|
|
||||||
isa = PBXShellScriptBuildPhase;
|
|
||||||
buildActionMask = 2147483647;
|
|
||||||
files = (
|
|
||||||
);
|
|
||||||
inputPaths = (
|
|
||||||
);
|
|
||||||
name = "📦 Copy Pods Resources";
|
|
||||||
outputPaths = (
|
|
||||||
);
|
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
|
||||||
shellPath = /bin/sh;
|
|
||||||
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests/Pods-Tests-resources.sh\"\n";
|
|
||||||
showEnvVarsInLog = 0;
|
|
||||||
};
|
|
||||||
FBC8982311CD4ED9A3006D45 /* 📦 Check Pods Manifest.lock */ = {
|
|
||||||
isa = PBXShellScriptBuildPhase;
|
isa = PBXShellScriptBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
|
@ -216,6 +189,36 @@
|
||||||
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
|
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
|
||||||
showEnvVarsInLog = 0;
|
showEnvVarsInLog = 0;
|
||||||
};
|
};
|
||||||
|
85E5D3885A03BFC23B050908 /* 📦 Copy Pods Resources */ = {
|
||||||
|
isa = PBXShellScriptBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
inputPaths = (
|
||||||
|
);
|
||||||
|
name = "📦 Copy Pods Resources";
|
||||||
|
outputPaths = (
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
shellPath = /bin/sh;
|
||||||
|
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests/Pods-Tests-resources.sh\"\n";
|
||||||
|
showEnvVarsInLog = 0;
|
||||||
|
};
|
||||||
|
C86216497B5A0BA9501E2C07 /* 📦 Embed Pods Frameworks */ = {
|
||||||
|
isa = PBXShellScriptBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
inputPaths = (
|
||||||
|
);
|
||||||
|
name = "📦 Embed Pods Frameworks";
|
||||||
|
outputPaths = (
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
shellPath = /bin/sh;
|
||||||
|
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests/Pods-Tests-frameworks.sh\"\n";
|
||||||
|
showEnvVarsInLog = 0;
|
||||||
|
};
|
||||||
/* End PBXShellScriptBuildPhase section */
|
/* End PBXShellScriptBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXSourcesBuildPhase section */
|
/* Begin PBXSourcesBuildPhase section */
|
||||||
|
|
@ -223,6 +226,7 @@
|
||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
1E3C51E919B46E370092B5E6 /* SDWebImageDownloaderTests.m in Sources */,
|
||||||
DA248D69195475D800390AB0 /* SDImageCacheTests.m in Sources */,
|
DA248D69195475D800390AB0 /* SDImageCacheTests.m in Sources */,
|
||||||
DA248D6B195476AC00390AB0 /* SDWebImageManagerTests.m in Sources */,
|
DA248D6B195476AC00390AB0 /* SDWebImageManagerTests.m in Sources */,
|
||||||
DA91BEBC19795BC9006F2536 /* UIImageMultiFormatTests.m in Sources */,
|
DA91BEBC19795BC9006F2536 /* UIImageMultiFormatTests.m in Sources */,
|
||||||
|
|
@ -246,18 +250,22 @@
|
||||||
DA248D4A1954721A00390AB0 /* Debug */ = {
|
DA248D4A1954721A00390AB0 /* Debug */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
|
ENABLE_TESTABILITY = YES;
|
||||||
|
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
|
||||||
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
};
|
};
|
||||||
name = Debug;
|
name = Debug;
|
||||||
};
|
};
|
||||||
DA248D4B1954721A00390AB0 /* Release */ = {
|
DA248D4B1954721A00390AB0 /* Release */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
|
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
|
||||||
};
|
};
|
||||||
name = Release;
|
name = Release;
|
||||||
};
|
};
|
||||||
DA248D65195472AA00390AB0 /* Debug */ = {
|
DA248D65195472AA00390AB0 /* Debug */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
baseConfigurationReference = 0EAE9F732E05E3878DC9D2D1 /* Pods-Tests.debug.xcconfig */;
|
baseConfigurationReference = 700B00151041D7EE118B1ABD /* Pods-Tests.debug.xcconfig */;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||||
|
|
@ -273,10 +281,6 @@
|
||||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
COPY_PHASE_STRIP = NO;
|
COPY_PHASE_STRIP = NO;
|
||||||
FRAMEWORK_SEARCH_PATHS = (
|
|
||||||
"$(inherited)",
|
|
||||||
"$(DEVELOPER_FRAMEWORKS_DIR)",
|
|
||||||
);
|
|
||||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||||
GCC_DYNAMIC_NO_PIC = NO;
|
GCC_DYNAMIC_NO_PIC = NO;
|
||||||
GCC_OPTIMIZATION_LEVEL = 0;
|
GCC_OPTIMIZATION_LEVEL = 0;
|
||||||
|
|
@ -294,8 +298,8 @@
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
INFOPLIST_FILE = "Tests/Tests-Info.plist";
|
INFOPLIST_FILE = "Tests/Tests-Info.plist";
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
|
|
||||||
ONLY_ACTIVE_ARCH = YES;
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
|
PRODUCT_BUNDLE_IDENTIFIER = "com.SDWebImage.${PRODUCT_NAME:rfc1034identifier}";
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
WRAPPER_EXTENSION = xctest;
|
WRAPPER_EXTENSION = xctest;
|
||||||
|
|
@ -304,7 +308,7 @@
|
||||||
};
|
};
|
||||||
DA248D66195472AA00390AB0 /* Release */ = {
|
DA248D66195472AA00390AB0 /* Release */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
baseConfigurationReference = 2FAA0419497C5AA7F0EA0E20 /* Pods-Tests.release.xcconfig */;
|
baseConfigurationReference = A0085854E7D88C98F2F6C9FC /* Pods-Tests.release.xcconfig */;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||||
|
|
@ -321,10 +325,6 @@
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
COPY_PHASE_STRIP = YES;
|
COPY_PHASE_STRIP = YES;
|
||||||
ENABLE_NS_ASSERTIONS = NO;
|
ENABLE_NS_ASSERTIONS = NO;
|
||||||
FRAMEWORK_SEARCH_PATHS = (
|
|
||||||
"$(inherited)",
|
|
||||||
"$(DEVELOPER_FRAMEWORKS_DIR)",
|
|
||||||
);
|
|
||||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||||
GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch";
|
GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch";
|
||||||
|
|
@ -335,7 +335,7 @@
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
INFOPLIST_FILE = "Tests/Tests-Info.plist";
|
INFOPLIST_FILE = "Tests/Tests-Info.plist";
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
|
PRODUCT_BUNDLE_IDENTIFIER = "com.SDWebImage.${PRODUCT_NAME:rfc1034identifier}";
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
VALIDATE_PRODUCT = YES;
|
VALIDATE_PRODUCT = YES;
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "0710"
|
LastUpgradeVersion = "0730"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
buildImplicitDependencies = "YES">
|
buildImplicitDependencies = "YES">
|
||||||
<BuildActionEntries>
|
|
||||||
<BuildActionEntry
|
|
||||||
buildForTesting = "YES"
|
|
||||||
buildForRunning = "YES"
|
|
||||||
buildForProfiling = "YES"
|
|
||||||
buildForArchiving = "YES"
|
|
||||||
buildForAnalyzing = "YES">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "537D957317ECC1FE0097C263"
|
|
||||||
BuildableName = "libSDWebImage+WebP.a"
|
|
||||||
BlueprintName = "SDWebImage+WebP"
|
|
||||||
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildActionEntry>
|
|
||||||
</BuildActionEntries>
|
|
||||||
</BuildAction>
|
</BuildAction>
|
||||||
<TestAction
|
<TestAction
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
|
|
@ -28,6 +12,16 @@
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
<Testables>
|
<Testables>
|
||||||
|
<TestableReference
|
||||||
|
skipped = "NO">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "DA248D52195472AA00390AB0"
|
||||||
|
BuildableName = "Tests.xctest"
|
||||||
|
BlueprintName = "Tests"
|
||||||
|
ReferencedContainer = "container:SDWebImage Tests.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</TestableReference>
|
||||||
</Testables>
|
</Testables>
|
||||||
<AdditionalOptions>
|
<AdditionalOptions>
|
||||||
</AdditionalOptions>
|
</AdditionalOptions>
|
||||||
|
|
@ -42,15 +36,6 @@
|
||||||
debugDocumentVersioning = "YES"
|
debugDocumentVersioning = "YES"
|
||||||
debugServiceExtension = "internal"
|
debugServiceExtension = "internal"
|
||||||
allowLocationSimulation = "YES">
|
allowLocationSimulation = "YES">
|
||||||
<MacroExpansion>
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "537D957317ECC1FE0097C263"
|
|
||||||
BuildableName = "libSDWebImage+WebP.a"
|
|
||||||
BlueprintName = "SDWebImage+WebP"
|
|
||||||
ReferencedContainer = "container:SDWebImage.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</MacroExpansion>
|
|
||||||
<AdditionalOptions>
|
<AdditionalOptions>
|
||||||
</AdditionalOptions>
|
</AdditionalOptions>
|
||||||
</LaunchAction>
|
</LaunchAction>
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
//
|
/*
|
||||||
// SDImageCacheTests.m
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage Tests
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Bogdan Poplauschi on 20/06/14.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
//
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#define EXP_SHORTHAND // required by Expecta
|
#define EXP_SHORTHAND // required by Expecta
|
||||||
|
|
||||||
|
|
@ -100,7 +100,7 @@ NSString *kImageTestKey = @"TestImageKey.jpg";
|
||||||
//- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock;
|
//- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock;
|
||||||
UIImage *imageForTesting = [self imageForTesting];
|
UIImage *imageForTesting = [self imageForTesting];
|
||||||
[self.sharedImageCache storeImage:imageForTesting forKey:kImageTestKey];
|
[self.sharedImageCache storeImage:imageForTesting forKey:kImageTestKey];
|
||||||
NSOperation *operation = [self.sharedImageCache queryDiskCacheForKey:kImageTestKey done:^(UIImage *image, SDImageCacheType cacheType) {
|
NSOperation *operation = [self.sharedImageCache queryDiskCacheForKey:kImageTestKey done:^(UIImage *image, NSData *data, SDImageCacheType cacheType) {
|
||||||
expect(image).to.equal(imageForTesting);
|
expect(image).to.equal(imageForTesting);
|
||||||
}];
|
}];
|
||||||
expect(operation).toNot.beNil;
|
expect(operation).toNot.beNil;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the SDWebImage package.
|
||||||
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
|
* (c) Matt Galloway
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define EXP_SHORTHAND // required by Expecta
|
||||||
|
|
||||||
|
|
||||||
|
#import <XCTest/XCTest.h>
|
||||||
|
#import <Expecta.h>
|
||||||
|
|
||||||
|
#import "SDWebImageDownloader.h"
|
||||||
|
|
||||||
|
@interface SDWebImageDownloaderTests : XCTestCase
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation SDWebImageDownloaderTests
|
||||||
|
|
||||||
|
- (void)setUp
|
||||||
|
{
|
||||||
|
[super setUp];
|
||||||
|
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)tearDown
|
||||||
|
{
|
||||||
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||||
|
[super tearDown];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testThatDownloadingSameURLTwiceAndCancellingFirstWorks {
|
||||||
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"];
|
||||||
|
|
||||||
|
NSURL *imageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage000.jpg"];
|
||||||
|
|
||||||
|
id token1 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL
|
||||||
|
options:0
|
||||||
|
progress:nil
|
||||||
|
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||||
|
XCTFail(@"Shouldn't have completed here.");
|
||||||
|
}];
|
||||||
|
expect(token1).toNot.beNil();
|
||||||
|
|
||||||
|
id token2 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL
|
||||||
|
options:0
|
||||||
|
progress:nil
|
||||||
|
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||||
|
[expectation fulfill];
|
||||||
|
}];
|
||||||
|
expect(token2).toNot.beNil();
|
||||||
|
|
||||||
|
[[SDWebImageDownloader sharedDownloader] cancel:token1];
|
||||||
|
|
||||||
|
[self waitForExpectationsWithTimeout:5. handler:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testThatCancelingDownloadThenRequestingAgainWorks {
|
||||||
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Correct image downloads"];
|
||||||
|
|
||||||
|
NSURL *imageURL = [NSURL URLWithString:@"http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.jpg?20120509154705"];
|
||||||
|
|
||||||
|
id token1 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL
|
||||||
|
options:0
|
||||||
|
progress:nil
|
||||||
|
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||||
|
XCTFail(@"Shouldn't have completed here.");
|
||||||
|
}];
|
||||||
|
expect(token1).toNot.beNil();
|
||||||
|
|
||||||
|
[[SDWebImageDownloader sharedDownloader] cancel:token1];
|
||||||
|
|
||||||
|
id token2 = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL
|
||||||
|
options:0
|
||||||
|
progress:nil
|
||||||
|
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||||
|
[expectation fulfill];
|
||||||
|
}];
|
||||||
|
expect(token2).toNot.beNil();
|
||||||
|
|
||||||
|
[self waitForExpectationsWithTimeout:5. handler:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
//
|
/*
|
||||||
// SDWebImageManagerTests.m
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage Tests
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Bogdan Poplauschi on 20/06/14.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
//
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#define EXP_SHORTHAND // required by Expecta
|
#define EXP_SHORTHAND // required by Expecta
|
||||||
|
|
||||||
|
|
@ -40,7 +40,10 @@ static int64_t kAsyncTestTimeout = 5;
|
||||||
|
|
||||||
NSURL *originalImageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage000.jpg"];
|
NSURL *originalImageURL = [NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage000.jpg"];
|
||||||
|
|
||||||
[[SDWebImageManager sharedManager] downloadImageWithURL:originalImageURL options:SDWebImageRefreshCached progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
[[SDWebImageManager sharedManager] loadImageWithURL:originalImageURL
|
||||||
|
options:SDWebImageRefreshCached
|
||||||
|
progress:nil
|
||||||
|
completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
expect(image).toNot.beNil();
|
expect(image).toNot.beNil();
|
||||||
expect(error).to.beNil();
|
expect(error).to.beNil();
|
||||||
expect(originalImageURL).to.equal(imageURL);
|
expect(originalImageURL).to.equal(imageURL);
|
||||||
|
|
@ -57,7 +60,10 @@ static int64_t kAsyncTestTimeout = 5;
|
||||||
|
|
||||||
NSURL *originalImageURL = [NSURL URLWithString:@"http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.png"];
|
NSURL *originalImageURL = [NSURL URLWithString:@"http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.png"];
|
||||||
|
|
||||||
[[SDWebImageManager sharedManager] downloadImageWithURL:originalImageURL options:SDWebImageRefreshCached progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
[[SDWebImageManager sharedManager] loadImageWithURL:originalImageURL
|
||||||
|
options:SDWebImageRefreshCached
|
||||||
|
progress:nil
|
||||||
|
completed:^(UIImage *image, NSData *data, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
|
||||||
expect(image).to.beNil();
|
expect(image).to.beNil();
|
||||||
expect(error).toNot.beNil();
|
expect(error).toNot.beNil();
|
||||||
expect(originalImageURL).to.equal(imageURL);
|
expect(originalImageURL).to.equal(imageURL);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>${EXECUTABLE_NAME}</string>
|
<string>${EXECUTABLE_NAME}</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
<string>com.SDWebImage.${PRODUCT_NAME:rfc1034identifier}</string>
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||||
<key>CFBundleInfoDictionaryVersion</key>
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
<string>6.0</string>
|
<string>6.0</string>
|
||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
//
|
/*
|
||||||
// UIImageMultiFormatTests.m
|
* This file is part of the SDWebImage package.
|
||||||
// SDWebImage Tests
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
//
|
*
|
||||||
// Created by Bogdan Poplauschi on 18/07/14.
|
* For the full copyright and license information, please view the LICENSE
|
||||||
//
|
* file that was distributed with this source code.
|
||||||
//
|
*/
|
||||||
|
|
||||||
#define EXP_SHORTHAND // required by Expecta
|
#define EXP_SHORTHAND // required by Expecta
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 25307796cfcf66cb5b98774e050e93f64e0f2cde
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the SDWebImage package.
|
||||||
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
||||||
|
* (c) Florent Vilmart
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
//! Project version number for WebImage.
|
||||||
|
FOUNDATION_EXPORT double WebImageVersionNumber;
|
||||||
|
|
||||||
|
//! Project version string for WebImage.
|
||||||
|
FOUNDATION_EXPORT const unsigned char WebImageVersionString[];
|
||||||
|
|
||||||
|
// In this header, you should import all the public headers of your framework using statements like #import <WebImage/PublicHeader.h>
|
||||||
|
|
||||||
|
#import <SDWebImage/SDWebImageManager.h>
|
||||||
|
#import <SDWebImage/SDImageCache.h>
|
||||||
|
#import <SDWebImage/UIImageView+WebCache.h>
|
||||||
|
#import <SDWebImage/SDWebImageCompat.h>
|
||||||
|
#import <SDWebImage/UIImageView+HighlightedWebCache.h>
|
||||||
|
#import <SDWebImage/SDWebImageDownloaderOperation.h>
|
||||||
|
#import <SDWebImage/UIButton+WebCache.h>
|
||||||
|
#import <SDWebImage/SDWebImagePrefetcher.h>
|
||||||
|
#import <SDWebImage/UIView+WebCacheOperation.h>
|
||||||
|
#import <SDWebImage/UIImage+MultiFormat.h>
|
||||||
|
#import <SDWebImage/SDWebImageOperation.h>
|
||||||
|
#import <SDWebImage/SDWebImageDownloader.h>
|
||||||
|
#if !TARGET_OS_TV
|
||||||
|
#import <SDWebImage/MKAnnotationView+WebCache.h>
|
||||||
|
#endif
|
||||||
|
#import <SDWebImage/SDWebImageDecoder.h>
|
||||||
|
#import <SDWebImage/UIImage+WebP.h>
|
||||||
|
#import <SDWebImage/UIImage+GIF.h>
|
||||||
|
#import <SDWebImage/NSData+ImageContentType.h>
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
//
|
|
||||||
// WebImage.h
|
|
||||||
// WebImage
|
|
||||||
//
|
|
||||||
// Created by Florent Vilmart on 2015-03-14.
|
|
||||||
// Copyright (c) 2015 Dailymotion. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
|
|
||||||
//! Project version number for WebImage.
|
|
||||||
FOUNDATION_EXPORT double WebImageVersionNumber;
|
|
||||||
|
|
||||||
//! Project version string for WebImage.
|
|
||||||
FOUNDATION_EXPORT const unsigned char WebImageVersionString[];
|
|
||||||
|
|
||||||
// In this header, you should import all the public headers of your framework using statements like #import <WebImage/PublicHeader.h>
|
|
||||||
|
|
||||||
#import <WebImage/SDWebImageManager.h>
|
|
||||||
#import <WebImage/SDImageCache.h>
|
|
||||||
#import <WebImage/UIImageView+WebCache.h>
|
|
||||||
#import <WebImage/SDWebImageCompat.h>
|
|
||||||
#import <WebImage/UIImageView+HighlightedWebCache.h>
|
|
||||||
#import <WebImage/SDWebImageDownloaderOperation.h>
|
|
||||||
#import <WebImage/UIButton+WebCache.h>
|
|
||||||
#import <WebImage/SDWebImagePrefetcher.h>
|
|
||||||
#import <WebImage/UIView+WebCacheOperation.h>
|
|
||||||
#import <WebImage/UIImage+MultiFormat.h>
|
|
||||||
#import <WebImage/SDWebImageOperation.h>
|
|
||||||
#import <WebImage/SDWebImageDownloader.h>
|
|
||||||
#if !TARGET_OS_TV
|
|
||||||
#import <WebImage/MKAnnotationView+WebCache.h>
|
|
||||||
#endif
|
|
||||||
#import <WebImage/SDWebImageDecoder.h>
|
|
||||||
#import <WebImage/UIImage+WebP.h>
|
|
||||||
#import <WebImage/UIImage+GIF.h>
|
|
||||||
#import <WebImage/NSData+ImageContentType.h>
|
|
||||||
Loading…
Reference in New Issue