Observed iOS background activity

Hi All,
Fairly new to using Realm for production applications. We’ve just released an iOS/Android app public that’s using Realm as a local database. Looking at our user analytics, we are seeing an odd behavior where users have background activity at random, this only happens in iOS platforms however and not in Android. Background Tasks capability is not enabled in iOS so I wasn’t expecting any background activity to take place. Is Realm still running processes in the background in some manner and if possible can we block them? This question originated as we started receiving background crashes in a significant number of our users. Appreciate any tips or pointers, thank you!

Welcome to the forums!

The question is a bit vague - it’s kind of like calling the auto mechanic and telling them your car goes ka-thunk, ka-thunk and asking what the issue is.

Yes, Realm has background processes but pretty much all apps have some kind of background processes running - whether it be coded in your app, something the OS is attending to, network calls, or from a SDK.

Is there any way you can narrow down what kind of processes they are and clarify if you only have Realm or do you perhaps have other SDK’s involved? Is this a purely local app or is there Sync’ing involved? Does you code use any kind of notifications?

Even better would be isolating a chunk of code that’s misbehaving and posting it here so we can take a look.

1 Like

Hi Jay, appreciate the response and the feedback on the question.

The chunk of code that’s triggering the crashes is this:

status = SecItemAdd(query as CFDictionary, nil)
        if status != errSecSuccess {
            fatalError("The encryption key could not be saved in the keychain") // you should throw an error or return nil so this can fail gracefully
        }
        assert(status == errSecSuccess, "Failed to insert the new key in the keychain")

Reading this Realm: Create reactive mobile apps in a fraction of the time I’m trying to understand whether the Data Protection capability on iOS is not enough (or even relevant), and if Realm is routinely trying to encrypt data while the device is locked is causing it to fail at that Fatal Error. I’ll add that when the app opens all data is there, so I’m considering replacing that line with a FatalError and letting it fail silently like the comment suggests, but just want to understand the processes that are going on.

To answer your specific questions:

  1. Purely local app, no Sync’ing involved
  2. We use Firebase and Pendo SDKs as well
  3. No notifications

Well. everything Firebase does is background tasks; literally everything. And that would also indicate it is not a purely local app as Firebase is an Online First database with some offline persistence for brief interruptions in connectivity.

The code in your question doesn’t appear to be directly related to Realm, so I would guess the background activity you’re seeing is 100% Firebase (because that’s just how it works!)

1 Like