Search code examples
iosrealmios-extensions

iOS - Data saved in shared group extension folder is deleted in low storage scenarios. is this normal?


I've had two users report to me that my database (realm) was suddenly empty, breaking the app.

My database is in a shared group extension folder so an extension can access it.

After talking with both of them, I determined that they both had very low storage on their phone <300mb.

I've been able to successfully reproduce the problem, by taking my phone down to ultra low storage, and then trying to install some apps from the app store. I get warnings on my phone saying it can't install the apps which are caused by the low storage.

When I go back to my app, the database is gone.

If I change my database to not be in the shared folder, it is never purged.

This is where I'm saving my data

 let fileURL = FileManager.default
                .containerURL(forSecurityApplicationGroupIdentifier: "group.myuniqueid.shared.database")!
                .appendingPathComponent("Library/Caches/default.realm")

Is this normal behaviour for shared group folders? Is data not safe there? Is this an issue with how Realm saves data to these folders?


Solution

  • I'm saving the database in a cache folder, which gets deleted.

    I've moved the database and it is no longer deleted

    let fileURL = FileManager.default
                    .containerURL(forSecurityApplicationGroupIdentifier: "group.myuniqueid.shared.database")!
                    .appendingPathComponent("default.realm")