Skip to content

Commit a81a160

Browse files
committed
Add option to request other type of PHAsset like Video during loading
1 parent 2cc4ff3 commit a81a160

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

SDWebImagePhotosPlugin/Classes/SDWebImagePhotosLoader.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@
3737
*/
3838
@property (nonatomic, strong, nullable) PHImageRequestOptions *imageRequestOptions;
3939

40+
/**
41+
Whether we request only `PHAssetMediaTypeImage` asset and ignore other types (video/audio/unknown).
42+
When we found other type, an error `SDWebImagePhotosErrorNotImageAsset` will be reported.
43+
Defaults to YES. If you prefer to load other type like video asset's poster image, set this value to NO.
44+
*/
45+
@property (nonatomic, assign) BOOL requestImageAssetOnly;
46+
4047
@end

SDWebImagePhotosPlugin/Classes/SDWebImagePhotosLoader.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ - (instancetype)init {
7777
requestOptions.version = PHImageRequestOptionsVersionCurrent;
7878
self.imageRequestOptions = requestOptions;
7979
self.operationsTable = [NSHashTable weakObjectsHashTable];
80+
self.requestImageAssetOnly = YES;
8081
self.fetchQueue = dispatch_queue_create("SDWebImagePhotosLoader", DISPATCH_QUEUE_SERIAL);
8182
#if SD_UIKIT
8283
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
@@ -155,8 +156,8 @@ - (BOOL)canRequestImageForURL:(NSURL *)url {
155156
PHFetchResult<PHAsset *> *fetchResult = [PHAsset fetchAssetsWithLocalIdentifiers:@[localIdentifier] options:fetchOptions];
156157
asset = fetchResult.firstObject;
157158
}
158-
// Only support image
159-
if (!asset || asset.mediaType != PHAssetMediaTypeImage) {
159+
// Check whether we should request only image asset
160+
if (!asset || (self.requestImageAssetOnly && asset.mediaType != PHAssetMediaTypeImage)) {
160161
// Call error
161162
NSError *error = [NSError errorWithDomain:SDWebImagePhotosErrorDomain code:SDWebImagePhotosErrorNotImageAsset userInfo:nil];
162163
if (completedBlock) {

0 commit comments

Comments
 (0)