mah*_*hib 5 nsfilemanager nsurlsession swift
你好,我使用 NSUelSession 下载大文件,在某些设备的 didFinishDownloadingToUrl 中随机出现此错误
错误代码 513:您无权访问“文档”
当我尝试将文件移动到文档目录时。当连接到 Xcode 时,我无法在实际设备上重现此错误,在运行 iOS 13 和 12 的随机设备上如何发生这种情况。问题是什么?这是我的 saveFile 函数
func saveFile(location : URL , fileName : String) {
let documentsPath = NSURL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])
let savedURL = documentsPath.appendingPathComponent(fileName)
do {
try self.fileManager.moveItem(atPath: location.relativePath , toPath: savedURL!.relativePath)
}
catch let error as NSError {
print("Ooops! Something went wrong: \(error)")
do {
SCLAlertView().showError("File Not Saved", subTitle: "Error Code \. (error.code) : \(error.localizedDescription)")
try fileManager.removeItem(at: location)
}
catch {
print(error.localizedDescription)
}
}
}
Run Code Online (Sandbox Code Playgroud)