我的代码在这里:
RLMRealmConfiguration *configuration = [RLMRealmConfiguration defaultConfiguration];
NSString *filePath = [NSString stringWithFormat:@"%@",configuration.fileURL];
NSString *dateBaseName = @"aaa";
configuration.fileURL = [NSURL URLWithString:[[[filePath stringByDeletingLastPathComponent]
stringByAppendingPathComponent:dateBaseName]
stringByAppendingPathExtension:@"realm"]];
configuration.encryptionKey = [self getEncriptionKey];
[RLMRealmConfiguration setDefaultConfiguration:configuration];
NSError *err = nil;
RLMRealm *realm = [RLMRealm realmWithConfiguration:configuration
error:&err];
if (!realm) {
NSLog(@"Error opening realm: %@", err);
}
但是当我迁移数据库时,似乎“领域文件解密失败”,应用程序崩溃了。
我的迁移代码在这里:
RLMRealmConfiguration *configuration = [RLMRealmConfiguration defaultConfiguration];
configuration.schemaVersion = 3;
configuration.encryptionKey = [self getEncriptionKey];
configuration.migrationBlock = migrationBlock;
[configuration setDeleteRealmIfMigrationNeeded:YES];
[RLMRealmConfiguration setDefaultConfiguration:configuration];
帮我 !!!