Keep .realm file upon app deletion


#1

Hello guys,

Is there any way to keep the .realm file even though user deleted the app? What I am trying to achieve is, the user can continue the previous “session” even though the user has deleted the app.

If there is no .realm file has been initiated before, it will create a default one, and if there was, it will reuse the previous .realm file

Can someone guide me on this? Thanks :slight_smile:


#2

Upon application delete, all data will be deleted.

However, you can sync the user data to the cloud, so the users data wont be lost (via realm cloud)
Or manage to sync the database to the users iCloud (via ice cream framework, with some limitations)
or you can build your own logic.


#3

Yes you can - you will need to make a backup of the realm file into the users iCloud storage and then when the app is reinstalled check if a file exists and copy it back to local and then open the realm. Presumably this is not a requirement for a synced solution given the user could just pull down a new version from the cloud.

I have an app in AppStore that uses Realm and allows the user to make backups and restore from backups. The backups are just local copies of the database but the user can choose to save them to their iCloud storage - assuming they have any. The only tricky consideration is making sure the app does not have any open Realms when making or restoring the backup.

It’s a bit of work copying files to/from iCloud storage if you’re not familiar with the storage APIs - you can’t assume the iCloud storage is available at any time so you have to request metadata and then request files be downloaded and then monitor things until the file is downloaded.

I might have some writeup on how to do that somewhere.