How to get an ALAsset URL from a PHAsset?

后端 未结 5 1099
灰色年华
灰色年华 2020-11-27 06:36

You can do it sneakily† using the undocumented PHAsset.ALAssetURL property, but I\'m looking for something documented.


† In Objective-C, this will

5条回答
  •  执念已碎
    2020-11-27 07:07

    I wanted to be able to get a URL for an asset too. However, I have realised that the localIdentifier can be persisted instead and used to recover the PHAsset.

    PHAsset* asset = [PHAsset fetchAssetsWithLocalIdentifiers:@[localIdentifier] options:nil].firstObject;
    

    Legacy asset URLs can be converted using:

    PHAsset* legacyAsset = [PHAsset fetchAssetsWithALAssetUrls:@[assetUrl] options:nil].firstObject;
    NSString* convertedIdentifier = legacyAsset.localIdentifier;
    

    (before that method gets obsoleted...)

    (Thanks holtmann - localIdentifier is hidden away in PHObject.)

提交回复
热议问题