所以我成功地使用魔法記錄與我的核心數據/ iCloud應用程序。 以下是我初始化:removeUbiquitousContentAndPersistentStoreAtURL「必須通過商店名稱」錯誤使用魔法記錄
- (NSString *) iCloudContainerID {
return [NSString stringWithFormat:@"iCloud.%@", [[NSBundle mainBundle] bundleIdentifier]];
}
- (NSString *) localStoreName {
return @"test.sqlite";
}
- (NSString *) iCloudContentNameKey {
return @"test";
}
- (void) setupCoreDataWithiCloud {
NSString *containerID = [self iCloudContainerID];
DDLogiCloud(@"Setting up Core Data with iCloud");
[MagicalRecord setupCoreDataStackWithiCloudContainer:containerID
contentNameKey:[self iCloudContentNameKey] // Must not contain dots
localStoreNamed:[self localStoreName]
cloudStorePathComponent:@"Documents/CloudLogs" // Subpath within your ubiquitous container that will contain db change logs
completion:^{
// This gets executed after all the setup steps are performed
// Uncomment the following lines to verify
NSLog(@"%@", [MagicalRecord currentStack]);
// NSLog(@"%i events", [Event countOfEntities]);
}];
}
使用上面的代碼中正確設置了核心數據和iCloud中。除了一些通知處理程序外,我還可以將記錄本地添加到核心數據,並通過iCloud將更改傳播到其他設備。
在測試過程中,以編程方式重置所有內容將會很好。這是我一直在試圖基於蘋果文檔重置CoreData/iCloud的例行:https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/UsingCoreDataWithiCloudPG/UsingSQLiteStoragewithiCloud/UsingSQLiteStoragewithiCloud.html#//apple_ref/doc/uid/TP40013491-CH3-SW33
- (bool) resetCoreDataWithiCloud {
NSString *containerID = [self iCloudContainerID];
NSURL *cloudURL = [NSPersistentStore MR_cloudURLForUbiqutiousContainer:containerID];
NSString *contentNameKey = [self iCloudContentNameKey];
NSDictionary *options = @{contentNameKey:NSPersistentStoreUbiquitousContentNameKey,cloudURL:NSPersistentStoreUbiquitousContentURLKey};
NSURL *storeURL = [NSPersistentStore MR_urlForStoreName:[self localStoreName]];
// NSURL *storeURL = [NSPersistentStore MR_urlForStoreName:[MagicalRecord defaultStoreName];
// [MagicalRecord cleanUp];
DDLogiCloud(@"Resetting CoreData and iCloud named %@ at %@",containerID,storeURL);
NSError *error;
bool removeResult = [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:storeURL options:options error:&error];
if (removeResult == NO) {
DDLogError(@"Could not remove iCloud Container. Reason: %@", error.localizedFailureReason);
}
return removeResult;
}
無論我怎麼努力,調用removeUbiquitous ...拋出的「錯誤在商店必須通過名稱'。
任何關於此的指導將有所幫助!