Swift AVAsset downloading from iCloud has no permission on iOS 14: error Code=257

Viewed 338

All my work worked well before iOS 14...

I display video from Library on my app. I succeeded to display all of them from iCloud or from the local storage. But since iOS 14, impossible to read them from iCloud and I don't find any solution...

The code:

    let options = PHVideoRequestOptions()
    options.isNetworkAccessAllowed = true
    options.version = .original
    options.progressHandler = { (progress, error, stop, info) in
        log.infoMessage("progress: \(progress)")
    }
    
    PHImageManager.default().requestAVAsset(forVideo: asset, options: options, resultHandler: {(avAsset: AVAsset?, audioMix: AVAudioMix?, info: [AnyHashable : Any]?) -> Void in
        if let asset = avAsset as? AVURLAsset {
            Queue.main {
                Player.shared.replaceAssetBy(AVPlayerItem(url: asset.url))
                self.playerLayer.player = Player.shared.player
                NotificationCenter.default.addObserver(self, selector: #selector(self.loopAction), name: .AVPlayerItemDidPlayToEndTime, object: Player.shared.player.currentItem)
            }
        }
    })

The error: FAILED Optional("Impossible d’ouvrir le fichier car vous ne disposez pas de l’autorisation nécessaire pour l’afficher.") -- error: Optional(Error Domain=NSCocoaErrorDomain Code=257 "Impossible d’ouvrir le fichier car vous ne disposez pas de l’autorisation nécessaire pour l’afficher." UserInfo={NSUnderlyingError=0x2814398c0 {Error Domain=NSOSStatusErrorDomain Code=-12203 "(null)"}})

Sorry The error is in french...

Just before some of you ask, I've already made the modification about rights with the .ReadWrite on the requestPermission new on iOS 14.

Regards,

1 Answers

I found two ways:

  • try options.deliveryMode = .highQualityFormat

or

  • use requestExportSession instad of requestAVAsset. Then use session.asset
Related