我有一個現有的應用程序與一個單一的核心數據存儲。這與蘋果稱之爲鞋盒應用程序類似。 已經存儲了很多記錄。我能夠輕鬆添加必要的代碼來獲得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