【发布时间】:2016-10-26 09:24:14
【问题描述】:
我从 Realm 0.9x но 2.0.x 更新了我的应用程序 现在我在 Crashlytics 上收到了大量来自 8、9 和 10 台 iOS 设备的关于致命异常的错误报告:
Fatal Exception: RLMException
Realm must not be nil
堆栈跟踪如下所示:
RLMObjectStore.mm 第 81 行 RLMGetObjects
RLMObject.mm 第 154 行 +[RLMObject objectsInRealm:withPredicate:]
RLMObject.mm 第 146 行 +[RLMObject objectsInRealm:where:args:]
RLMObject.mm 第 140 行 +[RLMObject objectsInRealm:where:]
Sessions.m 第 88 行 +[会话结果WithSessionsWhere:]
Sessions.m 第 128 行 +[会话活动会话]
Sessions.m 第 102 行 +[会话应用启动]
AppDelegate.m 第 60 行 -[AppDelegate 应用程序:didFinishLaunchingWithOptions:]
我无法在调试环境中重现错误。它触及了大约 30-40% 的用户(根本没有),而且我似乎只触及了老用户。
此方法中没有领域对象:
/**
* Create and returns Realm configuration for sessions database
*/
+(nonnull RLMRealmConfiguration*)realmConfigurationForSessions
{
RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
// Use the default directory, but replace the filename with the 'sessions.realm'
config.fileURL = [NSURL
URLWithString:[[[config.fileURL.absoluteString stringByDeletingLastPathComponent]
stringByAppendingPathComponent:@"sessions"]
stringByAppendingPathExtension:@"realm"]];
return config;
}
+(nullable RLMRealm*)realmForConfiguration:(nullable RLMRealmConfiguration*)config
{
if (!config) {
return nil;
}
NSError *error;
// Open the Realm with the configuration
RLMRealm *realm = [RLMRealm realmWithConfiguration:config
error:&error];
if (error) {
DLog(@"error: %@", error.localizedDescription);
}
return realm;
}
问题:1)这个奇怪问题的原因是什么? 2) 在这种情况下如何正确处理错误和 nil 领域值?
【问题讨论】:
标签: ios objective-c realm