我使用照片框架来保存和检索设备相册中的视频。
在保存我的视频时,我想添加一些自定义数据,例如:id、名称、描述等......并在从相册中检索这些数据时获取所有这些数据。
那可能吗 ?
我用来保存视频的代码是:
func saveVideo(url: URL, completionHandler: @escaping (Bool, Error?) -> ()) {
if assetCollection == nil {
return // If there was an error upstream, skip the save.
}
PHPhotoLibrary.shared().performChanges({
let assetChangeRequest = PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: url)
let assetPlaceholder = assetChangeRequest?.placeholderForCreatedAsset
let albumChangeRequest = PHAssetCollectionChangeRequest(for: self.assetCollection)
albumChangeRequest?.addAssets([assetPlaceholder] as NSFastEnumeration)
}, completionHandler: {
saved, error in
completionHandler(saved,error)
})
}