我正在尝试将 iCloud 集成到我的旧项目中,但同时尝试使用 MagicalRecord 更新数据库。当我不使用自定义 .sqlite 文件名时,iCloud 可以工作,但不能使用自定义文件名。在这里,有一些代码可以更好地解释我的意思。
// Load model. Don't use the standard 'merged model' of Magical Record, because that would include
// the Ensembles model. Don't want to merge models.
NSManagedObjectModel *model = [NSManagedObjectModel MR_newManagedObjectModelNamed:@"Polyglott.momd"];
[NSManagedObjectModel MR_setDefaultManagedObjectModel:model];
// Setup Core Data Stack
[MagicalRecord setShouldAutoCreateManagedObjectModel:NO];
// This is the custom file name
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"PolyglottModel"];
// Here is the default one
// [MagicalRecord setupAutoMigratingCoreDataStack];
// Setup Ensemble
// Here, I'm not sure which one is the right way
NSURL *url = [NSPersistentStore MR_urlForStoreName:@"PolyglottModel.sqlite"];
// NSURL *url = [NSPersistentStore MR_urlForStoreName:[MagicalRecord defaultStoreName]];
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Polyglott" withExtension:@"momd"];
self.cloudFileSystem = [[CDEICloudFileSystem alloc] initWithUbiquityContainerIdentifier:@"iCloud.de.thm.polyglott"];
self.ensemble = [[CDEPersistentStoreEnsemble alloc] initWithEnsembleIdentifier:@"PolyglottMR"
persistentStoreURL:url
managedObjectModelURL:modelURL
cloudFileSystem:self.cloudFileSystem];
self.ensemble.delegate = self;
// Listen for local saves, and trigger merges
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(localSaveOccurred:) name:CDEMonitoredManagedObjectContextDidSaveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cloudDataDidDownload:) name:CDEICloudFileSystemDidDownloadFilesNotification object:nil];
[self syncWithCompletion:nil];
leechPersistentStoreWithCompletion 和 mergeWithCompletion 都给我任何错误,但是当我请求数据库时,没有数据。
有什么想法或例子吗?非常感谢你。