如何使用Photos.Framework将自定义数据保存到PHAsset

时间:2017-09-21 22:58:54

标签: ios swift video phasset phphotolibrary

我使用照片框架来保存和检索设备相册中的视频。

在保存我的视频时,我想添加一些自定义数据,例如: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)
        })
    }

0 个答案:

没有答案