ios - 新版本如何防止核心数据问题

标签 ios iphone xcode core-data app-store

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/

相关文章:

ios - 错误 ITMS-90680 : "The binary you uploaded was invalid.”

iphone - genstrings 工具抛出异常,在解析 XCode 项目时中止

iphone - 以编程方式锁定和解锁 iPhone 屏幕

ios - 从 Storyboard加载时 XCTest 中出现 "Could not cast"错误

ios - 无法将类型 '[String]' 的值转换为预期的参数类型 'String' : while appending arrays to get data from Fireabse in table view cell

ios - 如何知道您构建的 iOS 应用程序是否适用于 64 位。

ios - 检索 UIPreviewInteraction 关联的触摸

iphone - 多个SKPayment交易

iphone - uitextfield positionFromPosition :offset not working emojis

ios - Xcode 生成错误 : Signing for AWSCore requires a development team