我正在尝试重命名文件(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 ““<strong>from_file”无法移动,因为您没有访问“<strong>My_folder”的权限。” UserInfo={NSSourceFilePathErrorKey=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/ My_folder / from_file , NSUserStringVariant=(Move), 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 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not allowed"}}
有趣的是,它在模拟器上运行良好。
有人可以帮我解决这个问题吗?(x-张贴在 Apple 论坛上)