Skip to content

Commit 95ffc7c

Browse files
committed
Update the readme about fetchOptions && imageRequestOptions demo usage
1 parent 19d2d05 commit 95ffc7c

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

README.md

+17-7
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,20 @@ imageView.sd_setImage(with: photosURL, placeholderImage: nil, context: [.customM
8989
#### Animated Images
9090
SDWebImagePhotosPlugin supports GIF images stored in Photos Library as well. Just use the same API as normal images to query the asset. We will query the image data and decode the animated images (compatible with `UIImageView` as well as [SDAnimatedImageView](https://github.com/rs/SDWebImage/wiki/Advanced-Usage#animated-image-50))
9191

92-
#### Custom Options
93-
To specify custom options like `PHFetchOptions` or `PHImageRequestOptions`. Either to change the property in loader, or provide a context options for each Photos Library image request.
92+
#### Fetch/Request Options
93+
To specify options like `PHFetchOptions` or `PHImageRequestOptions` for Photos Library. Either to change the correspond properties in loader, or provide a context options for each image request.
9494

9595
+ Objective-C
9696

9797
```objectivec
98-
// loader-level control
98+
// loader-level options
99+
// ignore iCloud Shared Album (`localIdentifier` Photos URL only)
100+
PHFetchOptions *fetchOptions = [PHFetchOptions new];
101+
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"sourceType != %d", PHAssetSourceTypeCloudShared];
99102
SDWebImagePhotosLoader.sharedLoader.fetchOptions = fetchOptions;
100-
// request-level control
103+
104+
// request-level options
105+
// allows iCloud Photos Library
101106
PHImageRequestOptions *requestOptions = [PHImageRequestOptions new];
102107
requestOptions.networkAccessAllowed = YES;
103108
[imageView sd_setImageWithURL:photosURL placeholderImage:nil context:@{SDWebImageContextPhotosImageRequestOptions: requestOptions, SDWebImageCustomManager: manager}];
@@ -106,9 +111,14 @@ requestOptions.networkAccessAllowed = YES;
106111
+ Swift
107112
108113
```swift
109-
// loader-level control
114+
// loader-level options
115+
// ignore iCloud Shared Album (`localIdentifier` Photos URL only)
116+
let fetchOptions = PHFetchOptions()
117+
fetchOptions.predicate = NSPredicate(format: "sourceType != %d", PHAssetSourceType.typeCloudShared.rawValue)
110118
SDWebImagePhotosLoader.shared.fetchOptions = fetchOptions
111-
// request-level control
119+
120+
// request-level options
121+
// allows iCloud Photos Library
112122
let requestOptions = PHImageRequestOptions()
113123
requestOptions.networkAccessAllowed = true
114124
imageView.sd_setImage(with: photosURL, placeholderImage: nil, context:[.photosImageRequestOptions: requestOptions, .customManager: manager])
@@ -117,7 +127,7 @@ imageView.sd_setImage(with: photosURL, placeholderImage: nil, context:[.photosIm
117127
## Tips
118128

119129
1. Since Photos Library image is already stored on the device disk. And query speed is fast enough for small resolution image. You can use `SDWebImageContextStoreCacheType` with `SDImageCacheTypeNone` to disable cache storage. And use `SDWebImageFromLoaderOnly` to disable cache query.
120-
2. If you use `PHImageRequestOptionsDeliveryModeOpportunistic` to load the image, PhotosKit will return a degraded thumb image firstly and again with the full pixel image. When the image is degraded, the loader completion block will set `finished = NO`. But this will not trigger the View Category completion block, only trigger a image refresh (like progressive loading behavior for network image using `SDWebImageProgressiveLoad`)
130+
2. If you use `PHImageRequestOptionsDeliveryModeOpportunistic` (by default) to load the image, PhotosKit will return a degraded thumb image firstly and again with the full pixel image. When the image is degraded, the loader completion block will set `finished = NO`. But this will not trigger the View Category completion block, only trigger a image refresh (like progressive loading behavior for network image using `SDWebImageProgressiveLoad`)
121131

122132
## Requirements
123133

0 commit comments

Comments
 (0)