如何从PHAsset获取ALAsset URL? [英] How to get an ALAsset URL from a PHAsset?

查看:180
本文介绍了如何从PHAsset获取ALAsset URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你可以使用偷偷溜溜†未记载的 PHAsset.ALAssetURL 属性,但我正在寻找记录的内容。

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

†在Objective-C中,这将有所帮助

† In Objective-C, this will help

@interface PHAsset (Sneaky)

@property (nonatomic, readonly) NSURL *ALAssetURL;

@end


推荐答案

创建assetURL通过利用 PHAsset 的localidentifier。
示例:
PHAsset.localidentifier 返回 91B1C271-C617-49CE-A074-E391BA7F843F / L0 / 001

Create the assetURL by leveraging the localidentifier of the PHAsset. Example: PHAsset.localidentifier returns 91B1C271-C617-49CE-A074-E391BA7F843F/L0/001

现在使用32个第一个字符来构建assetURL,例如:

Now take the 32 first characters to build the assetURL, like:

assets-library://asset/asset.JPG?id = 91B1C271-C617-49CE-A074-E391BA7F843F& ext = JPG

您可以更改扩展名 JPG ,具体取决于资产的UTI( requestImageDataForAsset 返回UTI),但在我的无论如何,测试assetsURL的扩展似乎都会被忽略。

You might change the extension JPG depending on the UTI of the asset (requestImageDataForAsset returns the UTI), but in my testing the extensions of the assetURL seems to be ignored anyhow.

这篇关于如何从PHAsset获取ALAsset URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆