【发布时间】:2015-04-12 22:39:36
【问题描述】:
我有一个显示文档列表的基本 iOS 应用程序。我正在尝试删除一个文档,但注意到下面的代码失败并显示“没有这样的文件或目录”如果该文档尚未从 iCloud 下载到设备。
文档可能非常大(40MB),我想避免下载文档只是为了删除它(这会占用用户数据计划的时间和带宽)。这可能吗?
[[[NSFileCoordinator alloc] initWithFilePresenter:nil]
coordinateWritingItemAtURL:documentURL
options:NSFileCoordinatorWritingForDeleting
writingItemAtURL:previewURL
options:NSFileCoordinatorWritingForDeleting
error:&error
byAccessor:^(NSURL *newDocumentURL, NSURL *newPreviewURL){
// Fails with "No such file" error if not yet downloaded from iCloud:
[[NSFileManager defaultManager] removeItemAtURL:newDocumentURL error:&error];
[[NSFileManager defaultManager] removeItemAtURL:newPreviewURL error:&error];
}];
完整的错误:
Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed.
(Cocoa error 4.)" UserInfo=0x14e82930 {NSUnderlyingError=0x14e69220
"The operation couldn’t be completed. No such file or directory",
【问题讨论】:
标签: ios cocoa-touch icloud nsfilemanager