簡體   English   中英

“無法打開該文件,因為您沒有查看它的權限。” 對於 iCloud 視頻

[英]"The file couldn’t be opened because you don’t have permission to view it." for iCloud Videos

已經有幾天了,我正在為這個問題而苦苦掙扎。 我正在從照片庫中拍攝視頻並使用它來創建縮略圖。 我的代碼運行正常,我正在獲取本地視頻的視頻數據和縮略圖。

但是當我 select 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.

我在這里發現了類似的問題,比如這個,但解決方案是在功能下打開沙盒(我在 xcode 12 中沒有找到)。 也試過這個,我得到了同樣的錯誤。 所有其他類似的問題都是針對應用程序沙箱之外的文件,但我的是來自照片庫的視頻。 我不應該能夠在我的應用程序中訪問它嗎? 下面是我的代碼。 請幫忙。

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

當我試圖在AVPlayer中播放來自 iCloud 的視頻時,我在 iOS 14 上看到了同樣的錯誤。 這似乎是照片框架中的一個錯誤,唯一對我有用的“解決方案”是請求最高質量的視頻。

options.deliveryMode =.highQualityFormat

請參閱@SwiftRabbit 關於使用 iCloud PHAsset 請求 AVAsset 的評論返回一個沒有 VideoTracks 的 AVAsset

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM