Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSFileManager moveItem抛出错误代码=513_Ios_Swift_Xcode_Nsfilemanager_Ios13 - Fatal编程技术网

Ios NSFileManager moveItem抛出错误代码=513

Ios NSFileManager moveItem抛出错误代码=513,ios,swift,xcode,nsfilemanager,ios13,Ios,Swift,Xcode,Nsfilemanager,Ios13,我正试图将一个文件从一个URL移动到另一个URL,但代码513出错。我知道这是一个NSFileWriteNoPermissionError。考虑到我一开始就创建了这个文件夹,我不认为这有什么可能 //self.video!.folderURL.path = /var/mobile/Containers/Data/Application/066BDB03-FD47-48D8-B6F8-932AFB174DF7/Documents/AV/769c504203024bae95b47d78d8fe902

我正试图将一个文件从一个URL移动到另一个URL,但代码
513
出错。我知道这是一个
NSFileWriteNoPermissionError
。考虑到我一开始就创建了这个文件夹,我不认为这有什么可能

//self.video!.folderURL.path = /var/mobile/Containers/Data/Application/066BDB03-FD47-48D8-B6F8-932AFB174DF7/Documents/AV/769c504203024bae95b47d78d8fe9029
try? fileManager.createDirectory(atPath: self.video!.folderURL.path, withIntermediateDirectories: true, attributes: nil)

// Update permission for AV folder
do {
     let parentDirectoryPath = self.video!.folderURL.deletingLastPathComponent().path
     let result = try fileManager.setAttributes([FileAttributeKey.posixPermissions: 0o777], ofItemAtPath: parentDirectoryPath)
        print(result)
     } catch {
        print("Error = \(error)")
     }

// sourceURL = file:///private/var/mobile/Containers/Data/PluginKitPlugin/50D8B8DB-19D3-4DD6-93DD-55F37CF87EA7/tmp/trim.6D37DFD2-5F27-4AB9-B478-5FED8AA6ABD7.MOV
// self.url = file:///var/mobile/Containers/Data/Application/066BDB03-FD47-48D8-B6F8-932AFB174DF7/Documents/AV/0b0b6803e891780850152eeab450a2ae.mov
do {
     try fileManager.moveItem(at: sourceURL, to: self.url)
   } catch {
     QLogTools.logError("Error moving video clip file \(error)")
   }
错误

Error Domain=NSCOCAERRORDOMAIN Code=513“trim.90A10B33-B884-419F-BAD9-65583531C3C3.MOV”无法移动,因为您没有访问“AV”的权限。“用户信息”={NSSourceFilePathErrorKey=/private/var/mobile/Containers/Data/PluginKitPlugin/0849234B-837C-43ED-BEDD-DE4F79E7CE96/tmp/trim.90A10B33-B884-419F-BAD9-65583531C3C3.MOV,NSUserStringVariant=( 移动

我尝试将我最初创建的文件夹的权限更改为0o777,但当我打印出其属性时,它返回511作为其权限


p.S:这只发生在iOS 13上。

我解决了我的问题,但可能与您所经历的有所不同:我在切换到
copyItem
时仍然存在问题。我在这里添加我的发现,作为一个答案,以防其他人像我一样偶然发现这个问题,并帮助他们解决问题

我的应用加载可从我的网站下载的自定义文件。使用iOS 13的下载管理器,这些文件首先复制到下载文件夹,然后可以由我的应用打开。但我的应用在尝试以与iOS 12相同的方式访问这些文件时出现权限错误

包括我在内。我需要调用
startAccessingSecurityScopedResource()
停止访问securityscopedresource()
,如下所示:

// source and destination are URLs
if source.startAccessingSecurityScopedResource() {
    try FileManager.default.moveItem(at: source, to: destination)
}
source.stopAccessingSecurityScopedResource()

这并不意味着这是iOS 13的新功能,但我认为不同的文件下载方式意味着需要考虑沙盒问题。

你怎么知道你有权访问源URL?@ElTomato我已经用错误更新了问题。我也遇到了同样的问题。你解决了吗?作为临时工单rkaround,我使用了
copy
方法而不是
move
方法,它是有效的。我遇到了这个问题,没有任何帮助。还有其他解决方案吗?这为我解决了它,尽管stopAccessingSecurityScopedResource()调用应该在括号内。在我的情况下不起作用。我尝试调用
startAccessingSecurityScopedResource()
在源和目标上,但在两个实例中都返回false。将其从
moveItem
更改为
copyItem
是我的修复方法(从UIImagePickerController选择中移动视频)