Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将视频资源保存到Gallery后检索视频资源_Ios_Swift_Ios13_Phphotolibrary - Fatal编程技术网

Ios 将视频资源保存到Gallery后检索视频资源

Ios 将视频资源保存到Gallery后检索视频资源,ios,swift,ios13,phphotolibrary,Ios,Swift,Ios13,Phphotolibrary,我正在尝试将一段视频保存到Gallery中,然后检索该资源,在ios 12中效果很好,现在在ios 13中测试它不再有效。视频已正确保存,但检索到的资源不是正确的资源,而是库中的另一个资源 PHPhotoLibrary.shared().performChanges({ PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: filePath) }) { completed, error in if com

我正在尝试将一段视频保存到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)
    }

}

我刚刚找到了这个问题的解决办法。您可以请求保存图像的本地标识符

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)
    }                        
}

创建日期不是执行此操作的方式。如果您希望在创建后访问资产,则不应丢弃创建请求的结果。而且视频可能仍在文件url处,那么为什么还要在您手中的时候从库中获取它呢?问题是FBSDK需要一个资产url来共享视频,我有一个内部董事会的视频是的,我就是这么说的。create请求返回一个值,但您将其丢弃。