手动迁移非版本管理对象模型

时间:2013-10-29 10:39:07

标签: iphone objective-c database core-data

这个问题标题可能看起来重复,但请仔细阅读我的问题,因为它与Core数据迁移有关。

我在大约2个月前在Apple商店上传了我的应用程序的第一个版本,然后在上个月上传了第二个版本。

现在我遇到的问题是我的新版本因核心数据而崩溃,因为新版本在现有实体中添加了一些属性。

当时我并不知道这样的迁移过程,但现在我不知道该怎么办,因为我的应用已经上线。

我必须上传一个必须具有核心数据兼容版本的新版本。 请指导我完成这个。

-(void)checkNeedForMigration{
NSURL *storeURL = [[self applicationDocumentsDirectory]              URLByAppendingPathComponent:@"ISB.sqlite"];
NSLog(@"database:%@",storeURL);


NSError *error = nil;
NSPersistentStoreCoordinator   *psc = [[NSPersistentStoreCoordinator alloc]     initWithManagedObjectModel:[self managedObjectModel]];

NSDictionary *sourceMetadata =
[NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType URL:storeURL error:&error];

NSManagedObjectModel *destinationModel=[psc managedObjectModel];
BOOL pscCompatibile = [destinationModel isConfiguration:Nil compatibleWithStoreMetadata:sourceMetadata];

NSManagedObjectModel *sourceModel=[NSManagedObjectModel mergedModelFromBundles:nil forStoreMetadata:sourceMetadata];

NSMappingModel *mappingModel =[NSMappingModel mappingModelFromBundles:nil forSourceModel:sourceModel destinationModel:destinationModel];

NSMigrationManager *migrationManager=[[NSMigrationManager alloc]initWithSourceModel:sourceModel destinationModel:destinationModel];

NSDictionary *optionDic=[[NSDictionary alloc]initWithObjectsAndKeys:[NSNumber numberWithBool:YES],NSInferMappingModelAutomaticallyOption,[NSNumber numberWithBool:YES],NSMigratePersistentStoresAutomaticallyOption, nil];

BOOL ok=[migrationManager migrateStoreFromURL:storeURL type:NSSQLiteStoreType options:optionDic withMappingModel:mappingModel toDestinationURL:storeURL destinationType:NSSQLiteStoreType destinationOptions:optionDic error:&error];}

现在获取null mappingModel ...

由于 的Pankaj

0 个答案:

没有答案
相关问题