Realm use local db instead of sync when network connection is unavailable?

As I see my realm does fall back to local realm when there is no internet connection to authorize Sync realm (even if it were successfully authorized before). It could be fine if local realm had any information copy of synced realm, but it does not. So Sync realm works only with internet connection or there is a way to keep it active even when device is offline?

Upvotes: 1

Views: 819

Answers (1)

AustinZ
AustinZ

Reputation: 1787

The way Realm Sync works is by ensuring that the copy of a Realm on your device and the copy of that same Realm on the server (and on any other devices) are always kept synchronized with each other. This means that you can use a synced Realm in exactly the same way as any other Realm even when there is no network connectivity at all. The synced Realm is the local Realm; you do not need to manually maintain two separate Realms containing the same data.

If you are offline when the app launches you can use the SyncUser.current API to get the previously logged-in user so you can open your synced Realms. (If you have logged in multiple users previously, you must use the SyncUser.all API instead to get a list of all the users and pick the one you want to use.)

Upvotes: 1

Related Questions