I forgot to do core data migration
在提交我的应用程序的新版本之前。安装旧版本并更新到新版本后,应用程序每次都会崩溃。
删除新版本并重新安装应用程序时,一切正常。我们正在谈论 App Store 上的产品版本。
你能告诉我如何解决这个问题吗?
最佳答案
您必须进行轻量级迁移:-
制作两个版本的数据模型[安全]
像这样的东西:-
+ (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if ([DBHelper sharedCoreDataInstance].objPersistentStoreCoordinator != nil) {
return [DBHelper sharedCoreDataInstance].objPersistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationLibraryDirectory] URLByAppendingPathComponent:@"yourdb.sqlite"];
NSError *error = nil;
NSDictionary *options = @{
NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES
};
[DBHelper sharedCoreDataInstance].objPersistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel:[self managedObjectModel]];
if(![[DBHelper sharedCoreDataInstance].objPersistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:storeURL
options:options
error:&error])
{
//Error for store creation should be handled in here
}
return [DBHelper sharedCoreDataInstance].objPersistentStoreCoordinator;
}
关于ios - 新版本如何防止核心数据问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26211344/