“无法打开该文件,因为您没有查看它的权限”对于 iCloud 视频

问题描述

已经有几天了,我正在为这个问题而苦苦挣扎。我正在从照片库中拍摄视频并使用它来创建缩略图。我的代码运行正常,我正在获取本地视频的视频数据和缩略图

但是当我选择 iCloud 中的视频时,我获得了视频数据,但无法创建缩略图
let img = try assetImgGenerate.copyCGImage(at: time,actualTime: nil)
返回错误The file Couldn’t be opened because you don’t have permission to view it.

在这里发现了类似的问题,比如 this 一个,但解决方案是在功能关闭沙盒(我在 xcode 12 中没有找到)。也试过 this 一个,我得到了同样的错误。 所有其他类似的问题都是针对应用程序沙箱之外的文件的,但我的是来自照片库的视频。我不应该能够在我的应用程序中访问它吗?下面是我的代码。请帮忙。

let options = PHVideoRequestOptions()
 options.isNetworkAccessAllowed = true
 options.progressHandler = {  (progress,error,stop,info) in
   print("progress: \(progress)")
 }

 //phAsset is asset fetched from photo library
 PHImageManager.default().requestAVAsset(forVideo: phAsset,options: options) 
 {(avAsset,mix,info) in

   let myAsset = avAsset as? AVURLAsset
   do {
    if let url = myAsset?.url{
        let videoData = try Data(contentsOf:url)
        dispatchQueue.global(qos: .background).async {
            let assetImgGenerate = AVAssetimageGenerator(asset: avAsset)
            assetImgGenerate.appliesPreferredTrackTransform = true
            let time = CMTime(seconds: 0.0,preferredTimescale: 600)
            do {
                let img = try assetImgGenerate.copyCGImage(at: time,actualTime: nil)
                let thumbnail = UIImage(cgImage: img)
                
            } catch {
                //here prints : "The file Couldn’t be opened because you don’t have permission to view it."
                print(error.localizedDescription)
            }
        }
        
    }
 } catch  {
    print("exception catch at block - while uploading video")
 }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)