【发布时间】:2012-01-29 06:44:49
【问题描述】:
我有一个具有单个核心数据存储的现有应用程序。它类似于 Apple 所说的鞋盒应用程序。 已经存储了许多记录。我能够轻松添加必要的代码来进行 iCloud 集成设置。
我在运行 iOS5 的 iPod touch 和 iPad 上构建了新应用程序。
iPod 有现有数据。但是数据不会显示在 iPad 上。 该应用程序启用了 iTunes 文件共享,因此我通过 iTunes 将 sqlite db 放在两台设备上。
现在我尝试进行更改,看看 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 代码和一些关于您的数据存储如何工作的描述。