Skip to content

Commit

Permalink
Allow RCTPhotoLibraryImageLoader to handle assets-library request
Browse files Browse the repository at this point in the history
Reviewed By: javache

Differential Revision: D3503380

fbshipit-source-id: 8f8eb545343738906e44ee01aa4ba23755a209c7
  • Loading branch information
nathanajah authored and samerce committed Aug 23, 2016
1 parent e2dbc43 commit 45f0e5d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Libraries/CameraRoll/RCTPhotoLibraryImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ @implementation RCTPhotoLibraryImageLoader

- (BOOL)canLoadImageURL:(NSURL *)requestURL
{
return [requestURL.scheme caseInsensitiveCompare:@"ph"] == NSOrderedSame;
if (![PHAsset class]) {
return NO;
}
return [requestURL.scheme caseInsensitiveCompare:@"assets-library"] == NSOrderedSame ||
[requestURL.scheme caseInsensitiveCompare:@"ph"] == NSOrderedSame;
}

- (RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
Expand All @@ -38,10 +42,17 @@ - (RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
// The 'ph://' prefix is used by FBMediaKit to differentiate between
// assets-library. It is prepended to the local ID so that it is in the
// form of an, NSURL which is what assets-library uses.
NSString *phAssetID = [imageURL.absoluteString substringFromIndex:@"ph://".length];
PHFetchResult *results = [PHAsset fetchAssetsWithLocalIdentifiers:@[phAssetID] options:nil];
NSString *assetID = @"";
PHFetchResult *results;
if ([imageURL.scheme caseInsensitiveCompare:@"assets-library"] == NSOrderedSame) {
assetID = [imageURL absoluteString];
results = [PHAsset fetchAssetsWithALAssetURLs:@[imageURL] options:nil];
} else {
assetID = [imageURL.absoluteString substringFromIndex:@"ph://".length];
results = [PHAsset fetchAssetsWithLocalIdentifiers:@[assetID] options:nil];
}
if (results.count == 0) {
NSString *errorText = [NSString stringWithFormat:@"Failed to fetch PHAsset with local identifier %@ with no error message.", phAssetID];
NSString *errorText = [NSString stringWithFormat:@"Failed to fetch PHAsset with local identifier %@ with no error message.", assetID];
completionHandler(RCTErrorWithMessage(errorText), nil);
return ^{};
}
Expand Down

0 comments on commit 45f0e5d

Please sign in to comment.