将视频资产保存到图库后检索

时间:2019-11-08 15:50:58

标签: ios swift ios13 phphotolibrary

我正在尝试将视频保存到Gallery,然后在ios 12中检索资产,效果很好,现在在ios 13中对其进行测试不再起作用。视频已正确保存,但检索到的资产不是正确的资产,而是库中的另一资产。

PHPhotoLibrary.shared().performChanges({
    PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: filePath)
}) { completed, error in
    if completed {
        let fetchOptions = PHFetchOptions()
        fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]

        let fetchResult = PHAsset.fetchAssets(with: .video, options: fetchOptions).lastObject
        GeneralUtils().shareVideoFacebook(fetchResult!, self)
    }

}

1 个答案:

答案 0 :(得分:0)

我刚刚找到了解决此问题的方法。您可以要求保存的图像的本地标识符。

var id: String?
PHPhotoLibrary.shared().performChanges({
    let collection = PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: filePath)
    id = collection?.placeholderForCreatedAsset?.localIdentifier
}) { completed, error in
    if completed {
        let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: [id!], options: .none).firstObject
        GeneralUtils().shareVideoFacebook(fetchResult!, self)
    }                        
}
相关问题