【问题标题】:"The file couldn’t be opened because you don’t have permission to view it." for iCloud Videos“无法打开该文件,因为您无权查看它。”用于 iCloud 视频
【发布时间】:2021-08-20 07:23:44
【问题描述】:

已经有几天了,我正在努力解决这个问题。我正在从照片库中拍摄视频并使用它来创建缩略图。我的代码工作正常,我正在获取本地视频的视频数据和缩略图。

但是当我选择 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")
 }
}

【问题讨论】:

  • 你怎么知道应用已经完成了剪辑的下载?
  • 我正在打印进度。我可以看到它在控制台中完成。我也是在下载完成后才获得AVasset,对吗?

标签: ios swift icloud phphotolibrary


【解决方案1】:

当我尝试在AVPlayer 中播放来自 iCloud 的视频时,我在 iOS 14 上看到了同样的错误。这似乎是照片框架中的一个错误,唯一对我有用的“解决方案”就是请求最高质量的视频。

options.deliveryMode = .highQualityFormat

查看@SwiftRabbit 对Request AVAsset using iCloud PHAsset returns an AVAsset with no VideoTracks的评论

【讨论】:

  • 感谢您的回答,我会尝试使用您的解决方案修复我的代码。
猜你喜欢
  • 2014-07-09
  • 2020-06-09
  • 2020-03-12
  • 2016-03-10
  • 1970-01-01
  • 2015-02-23
  • 2015-04-15
  • 1970-01-01
相关资源
最近更新 更多