How to get a PHAsset from a NSItemProvider URL?

Hi,


I'd like to find out the local identifier of an asset so that I can do something about it from my app extension through my container app.



Basically, I can get the URL frm the NSItem provider but this url starts with something like:


file:///var/mobile/Media/PhotoData/OutgoingTemp/14565673-FE65-4184-BC97-A9D4A112472F.JPG



but when I enumerate the PHAssets using the following


PHFetchOptions *option = [PHFetchOptions new];

option.includeHiddenAssets = YES;

PHFetchResult *allAssets = [PHAsset fetchAssetsWithOptions:option];

[allAssets enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {



[[Defaults defaultPHImageManager] requestImageDataForAsset:asset options:imageRequestOptions resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {

DBG(@"File URL = %@", info[@"PHImageFileURLKey"]);

}];

}




The URLs I'm getting doesn't match the url from the app extension and they start with something like:

file:///var/mobile/Media/DCIM/100APPLE/IMG_0012.JPG




How do I load a PHAsset from the app etension and pass the local identifier to my app?

Replies

Any luck?

This is not supported for the simple reason, that an NSItemProvider photo does not have to be in the IOS Photo Library. If you e.g. share a photo you are editing in Pixelmator, this photo is not part of the iOS Photo Library. The idea to match an NSItemProvider to a corresponding PHAsset based on the filename is slow and will not work on all iOS versions. What are you trying to achieve here?

The reason I want to get PHAsset from an NSItemProvider that shared by Photos app is because I want to get a copy of user's Live Photo instead of a copy of static photo.