文件重命名失败,设备上的NSCocoaErrorDomain Code = 513

时间:2017-09-20 12:23:44

标签: ios uidocument nsfilewrapper

我尝试重命名文件(包含FileWrapper子类的UIDocument),如下所示:

coordinationQueue.async {
    var error: NSError? = nil
    let fileCoordinator = NSFileCoordinator(filePresenter: self)
    fileCoordinator.coordinate(readingItemAt: url, options: .withoutChanges, 
      writingItemAt: targetURL, options: .forMoving, error: &error) { fromURL, toURL in
        do {
            fileCoordinator.item(at: fromURL, willMoveTo: toURL)
            try FileManager().moveItem(at: fromURL, to: toURL)
            fileCoordinator.item(at: fromURL, didMoveTo: toURL)

            // Success!
        } catch {
            // Handle error
        }
    }
    if let error = error {
        // Handle error
    }
}

...但它在moveItem失败,出现以下错误:

  

错误域= NSCocoaErrorDomain代码= 513"由于您无权访问“ My_folder ”,因此无法移动“ from_file ”。 #34; UserInfo = {NSSourceFilePathErrorKey = / private / var / mobile / Library / Mobile Documents / com~apple~CloudDocs / My_folder / from_file ,NSUserStringVariant =(       移动   ),NSDestinationFilePath = / private / var / mobile / Library / Mobile Documents / com~apple~CloudDocs / My_folder / to_file ,NSFilePath = / private / var / mobile / Library / Mobile Documents / com~apple~CloudDocs / My_folder / from_file ,NSUnderlyingError = 0x1c1240ab0 {错误域= NSPOSIXErrorDomain代码= 1"操作不被允许"} }

有趣的是,它在模拟器上运行良好。

有人可以帮我解决这个问题吗? (x-posted在Apple论坛上发布)

0 个答案:

没有答案