我有一个现有的应用程序与一个单一的核心数据存储。这与苹果称之为鞋盒应用程序类似。 已经存储了很多记录。我能够轻松添加必要的代码来获得iCloud集成设置。iCloud和现有的Core数据存储“鞋盒”应用程序
我在我的iPod touch和iPad上构建了新应用程序,这两个应用程序都运行iOS5。
iPod具有现有数据。但是这些数据并没有显示在iPad上。 该应用程序启用了iTunes文件共享功能,因此通过iTunes将两台设备上的sqlite数据库都删除。
现在我尝试进行更改,看看iCloud是否会保持同步。它不是。
如何在两台设备上获得现有数据,然后让iCloud从这一点保持同步。
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *cloudURL = [fileManager URLForUbiquityContainerIdentifier:@"ABCD1234.com.yourcompany.appID"];
NSDictionary *options = nil;
if (nil != cloudURL) {
NSString *coreDataCloudContent = [[cloudURL path] stringByAppendingPathComponent:@"data"];
cloudURL = [NSURL fileURLWithPath:coreDataCloudContent];
options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
@"myApp.store", NSPersistentStoreUbiquitousContentNameKey,
cloudURL, NSPersistentStoreUbiquitousContentURLKey,
nil];
}
else {
options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
nil];
}
而且我这个加入到managedObjectContext的通知:
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(mergeChangesFrom_iCloud:) name:NSPersistentStoreDidImportUbiquitousContentChangesNotification object:coordinator];
有使用我的应用程序数千人,并已进入了大量的数据。他们不想再次输入。我想提供启用了iCloud的应用程序的这个新版本,但是直到我可以将数据显示在两者上并保持同步,没有任何意义。
“我能够轻松添加必要的代码来获得iCloud集成设置” - 也许它不像您想象的那么容易;)。你将需要包含一些你的iCloud代码以及你的数据存储如何工作的一些描述。 – jrturton 2012-01-29 07:44:29
你是怎么做到的? – 2012-04-13 03:52:11