ios - Realm must not be nil -
i updated app realm 0.9x но 2.0.x have lot of bug reports 8, 9 , 10 ios devices on crashlytics fatal exception:
fatal exception: rlmexception realm must not nil
stack trace looks this:
rlmobjectstore.mm line 81 rlmgetobjects
rlmobject.mm line 154 +[rlmobject objectsinrealm:withpredicate:]
rlmobject.mm line 146 +[rlmobject objectsinrealm:where:args:]
rlmobject.mm line 140 +[rlmobject objectsinrealm:where:]
sessions.m line 88 +[sessions resultwithsessionswhere:]
sessions.m line 128 +[sessions activesession]
sessions.m line 102 +[sessions applaunched]
appdelegate.m line 60 -[appdelegate application:didfinishlaunchingwithoptions:]
i can't reproduce bug on debug environment. touched around 30-40% of users (not @ all), , looks old users touched.
there no realm object in method:
/** * create , returns realm configuration sessions database */ +(nonnull rlmrealmconfiguration*)realmconfigurationforsessions { rlmrealmconfiguration *config = [rlmrealmconfiguration defaultconfiguration]; // use default directory, replace filename '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 realm configuration rlmrealm *realm = [rlmrealm realmwithconfiguration:config error:&error]; if (error) { dlog(@"error: %@", error.localizeddescription); } return realm; }
questions: 1) cause of strange issue? 2) how can handle error , nil realm value in situation?
that exception occurs in pretty straightforward case. error occurred , resulted in rlmrealm
instance not being created when should have been.
with information you've provided, it's possible way you're constructing fileurl
property might not succeeding in cases.
my recommendations:
- use
[nsurl fileurlwithpath:]
instead of[nsurl urlwithstring:]
. 1 better optimized file paths opposed web urls. - use
config.fileurl.path
instead ofconfig.fileurl.absolutestring
. more information why, check answer. - for consistency's sake, use
[nsurl urlbyappendingpathcomponent:]
opposed[nsstring stringbyappendingpathcomponent:]
.
i hope helped! let me know if need additional clarification!
Comments
Post a Comment