Search code examples
iosobjective-cfirebasefirebase-realtime-databasefirebase-crash-reporting

assertUnfrozen on iOS


I use a Firebase realtime database in an iOS app and I get a crash report through Firebase's crash reporting at [FIRDatabase assertUnfrozen] called from [FIRDatabase setPersistenceEnabled:]. (There's also a variation of these reports where the source is FIRDatabaseConfig rather than FIRDatabase)

In my app delegate's application:didFinishLaunchingWithOptions: method, I load the Firebase config from a file and then set persistence to enabled. For about 1 out of every 200 users this causes the crash with assertUnfrozen. Am I initializing Firebase in an incorrect way, or is there anyone with an idea about what's going wrong?


Solution

  • Calls to setPersistenceEnabled must be made before any other usage of FIRDatabase instance.This is reason for the crash, so check whether you are using FIRDatabase instance before calling setPersistenceEnabled.

    In my case, I was using FIRDatabase instance in applicationDidEnterBackground and I had used setPersistenceEnabled in launchController.As soon as we open the app, before launchController is called, make the app go into background.Then, applicationDidEnterBackground gets called and FIRDatabase instance is used before calling setPersistenceEnabled.So, I removed firebase code from applicationDidEnterBackground and wrote it after setPersistenceEnabled is called.