Luc*_*cio 5 identifier ios alasset phasset cross-device
我实际上正在创建一个iOS应用程序,并希望在SQLite数据库中存储有关Photo Library图片的一些细节.我也希望能够在用户拥有的不同设备上共享这些数据(想象有人想在他的iPhone上重新组织图片,并希望在他的iPad中检索相同的订单).
我搜索了Apple文档,但未找到任何PHAsset跨设备共享的标识符.我也试图检查PHImageFileURLKey,hashValue或localIdentifier的PHAsset地方共享,但他们都不是.
有人已经做过这样的事吗?
自 iOS 15 起,有一个可在所有设备上使用的标识符:https://developer.apple.com/documentation/photokit/phcloudidentifier
API 非常简单。这个想法是,您存储并同步云标识符,然后使用它们来检索本地标识符,然后您可以像以前一样将其与现有 API 一起使用。您可以批量请求云标识符,如下所示:
let localIdentifiers = <your-list-of-local-identifiers>
let mappings: [String: Result<PHCloudIdentifier, Error>] =
PHPhotoLibrary.shared().cloudIdentifierMappings(forLocalIdentifiers: localIdentifiers)
Run Code Online (Sandbox Code Playgroud)
您可以使用该stringValue属性来存储此类标识符。
反之亦然(假设您有一个cloudIdentifiers包含标识符字符串值的列表):
let localIdentifiers: [PHCloudIdentifier: Result<String, Error>]
= PHPhotoLibrary
.shared()
.localIdentifierMappings(
for: cloudIdentifiers.map(PHCloudIdentifier.init(stringValue:)))
Run Code Online (Sandbox Code Playgroud)
可能会发生什么错误?
我通过实验得出的其他见解:
| 归档时间: |
|
| 查看次数: |
632 次 |
| 最近记录: |