微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决“无法打开该文件,因为您没有查看它的权限”对于 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 举报,一经查实,本站将立刻删除。