创建addPersistentStoreWithType方法使用的选项Dictionary时,应用程序崩溃

Ali*_*tar 5 app-store core-data-migration nspersistentstore keychainitemwrapper encrypted-core-data-sql

encrypted-core-data用来加密所有持久化的数据,以前很简单CoreData.persistentStoreCoordinator创建代码如下.

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (_persistentStoreCoordinator != nil) {
    return _persistentStoreCoordinator;
}

NSURL *oldStoreURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"VistaJetApp.sqlite"];
NSURL *newStoreURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"VistaJet.sqlite"];
NSError *error = nil;

NSString *currentPassword = [[VJAesCryptoWrapper getInstance] getCurrentPassword];
NSDictionary *options = [self getEncryptedStoreOptionsWithPassword:currentPassword andDatabaseStore:newStoreURL];

_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];

//if old store not exists , it means fresh installation
if([[NSFileManager defaultManager] fileExistsAtPath:oldStoreURL.path] == NO) {             
    if (![_persistentStoreCoordinator addPersistentStoreWithType:EncryptedStoreType configuration:nil URL:newStoreURL options:options error: &error]) {         
    }        
} else {

    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:oldStoreURL options:@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} error: &error]) {                     
    }

    NSPersistentStore *oldUnsecureStore = [_persistentStoreCoordinator persistentStoreForURL:oldStoreURL];
    [ConsoleLogger logText:[NSString stringWithFormat:@"Migration started"]];

    //start migration
    if(![_persistentStoreCoordinator migratePersistentStore:oldUnsecureStore toURL:newStoreURL options:options withType:EncryptedStoreType error:&error]) {


    } else {
        [[NSFileManager defaultManager] removeItemAtURL:oldStoreURL error:nil];
    }

}

return _persistentStoreCoordinator;

}
Run Code Online (Sandbox Code Playgroud)

创建选项字典

- (NSDictionary*)getEncryptedStoreOptionsWithPassword:(NSString*)password andDatabaseStore:(NSURL*)storeUrl {
return @{ EncryptedStorePassphraseKey: password,
          EncryptedStoreDatabaseLocation: storeUrl,
          NSMigratePersistentStoresAutomaticallyOption:@YES,
          NSInferMappingModelAutomaticallyOption:@YES
          };
}
Run Code Online (Sandbox Code Playgroud)

我正在使用密钥链保存密码,KeychainItemWrapper而我的代码正好在getEncryptedStoreOptionsWithPassword:currentPassword方法上崩溃.应用程序是实时的,我无法重现崩溃,但在崩溃问题上,它显示出如此多的崩溃

crashlytics崩溃日志图像

还使用AESCrypt加密密码然后使用保存到钥匙串KeychainItemWrapper.

观察:
当我们使用分发配置文件在测试航班上传构建时,才会显示崩溃关系显示的崩溃.

据崩溃论者报道,iOS 11上发生了100%的崩溃事件

Pop*_*dic 0

我认为这是您所看到的 iOS 10 中的一个已知错误,有一个解决方法:启用“钥匙串共享”(在 Xcode 中的应用程序 -> 功能选项卡下)。

KeychainItemWrapper 在 iOS10 上崩溃