【发布时间】:2014-05-22 03:55:04
【问题描述】:
我正在寻找一种更好的方法来将一堆文件从我的 iCloud 容器下载到我的沙盒。这是我目前使用的:
for (FileAttachments *fileLink in items) {
NSURL *cloudFileURL = [fileLink urlForCloudAttachmentWithName];
NSURL *fileURL = [backupCloudLocalDirectoryURL URLByAppendingPathComponent: fileLink.fileName];
NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
[fileCoordinator coordinateReadingItemAtURL:fileURL options:NSFileCoordinatorReadingWithoutChanges error:&error
byAccessor:^(NSURL *newURL) {
NSError *blockError = nil;
[fileManager copyItemAtURL:cloudFileURL toURL:fileURL error:&blockError];
}];
}
}
以这种方式复制 iCloud 项目有什么问题吗?在生产中,我有一些用户抱怨他们的所有文件都没有下载。改用NSFileManager's startDownloadingUbiquitousItemAtURL:error 会更好吗?如果是这样,为什么?
谢谢。
【问题讨论】:
-
在运行上面的代码之前,你有没有做任何事情来确保文件已经下载?
-
或者更好的说法是,如何找到云文件的 URL,以便知道要从哪个 URL 复制?
-
从文件添加到应用程序时开始,URL 就保存在 Core Data 中。他们持有对该文件的有效引用;只是在某些情况下它们没有被下载,而且不可复制。它不应该从 fileCoordinator coordinateReadingItemAtURL 块工作吗?
标签: ios icloud nsfilemanager nsfilecoordinator