我在我的应用程序中有基本的iCloud支持(同步更改,无处不在等),但到目前为止一个重要的遗漏是缺乏对云中存在(或有变化)的文件的"下载"支持,但不是与当前磁盘上的内容同步.
我根据一些Apple提供的代码,在我的应用程序中添加了以下方法,并进行了一些调整:
下载方式:
- (BOOL)downloadFileIfNotAvailable:(NSURL*)file {
NSNumber* isIniCloud = nil;
if ([file getResourceValue:&isIniCloud forKey:NSURLIsUbiquitousItemKey error:nil]) {
// If the item is in iCloud, see if it is downloaded.
if ([isIniCloud boolValue]) {
NSNumber* isDownloaded = nil;
if ([file getResourceValue:&isDownloaded forKey:NSURLUbiquitousItemIsDownloadedKey error:nil]) {
if ([isDownloaded boolValue])
return YES;
// Download the file.
NSFileManager* fm = [NSFileManager defaultManager];
NSError *downloadError = nil;
[fm startDownloadingUbiquitousItemAtURL:file error:&downloadError];
if (downloadError) {
NSLog(@"Error occurred starting download: %@", downloadError);
}
return NO;
}
}
}
// Return …Run Code Online (Sandbox Code Playgroud) 我一直试图创建一个简单的UIManagedDocument库样式应用程序(保存到iCloud的单独文档)非常失败.
我对以下内容感到困惑:
难道我的子类UIManagedDocument,并成立了persistentStoreCoordinator,ManagedObjectModel与ManagedObjectContext这个子类中,或者这些应该是内部配置的AppDelegate(如果是的话,我怎么去刷新persistentStoreCoordinator看新的文件-看来,一旦已经读了persistentStore这我不能让它读取新的持久存储)?