AVAssetExportSession not working on devices, but working on simulator (AVFoundationErrorDomain Code = -11800, Unknown Error code -12780)

后端 未结 2 406
长发绾君心
长发绾君心 2021-01-29 04:39

EDIT: To make things easier to anyone interested in checking out this problem, I added a demo project to this github repository.

Issue<

2条回答
  •  天命终不由人
    2021-01-29 05:03

    The problem is that you're appending string to another string resulting in wrong path to the file like file:///var/mobile/Containers/Data/Application//DocumentsFinalVideo.mov

    You should use appendingPathComponent() instead:

    func createPath() -> URL {
        let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
        let documentDirectory = URL(fileURLWithPath: paths.first!)
        let url = documentDirectory.appendingPathComponent("FinalVideo.mov")
    
        if FileManager.default.fileExists(atPath: url.path) {
            try? FileManager.default.removeItem(at: url)
        }
    
        return url
    }
    

提交回复
热议问题