How to persist data locally with firebase realtime database in react native? - firebase

I am a newbie to mobile development and I am building a mobile game in react native for android devices where I want to store user centric information such as score for different levels in realtime database in firebase. My users would be in playing game in restricted internet connectivity(where user connects to internet once in few days) and I want a mechanism such that app should store data locally even when the application "RESTARTS" or the app is killed by user and when internet connectivity comes, should be able to push all data on server.
I have two questions:
Can I some how automatically send data to server without user opening the app when the internet connectivity is established?
I found support for enabling offline data persistence in case of application or operating system restart for android in Java and kotlin
(https://firebase.google.com/docs/database/android/offline-capabilities), but did not find support for react native. I have gone through documentation of React Native Firebase library (https://rnfirebase.io/docs/v5.x.x/database/reference/database), but did find option to enable data persistence option for case when application/os restarts. Is there any workaround for this?

What you are looking for is Cloud Firestore, it has data persistence built-in so you won't have to worry. Use react-native-firebase for that, it has an absolutely beautiful documentation and guides and the community is very helpful too.
To sync your local data with the server without user opening app, you'll need to delve into the native side and make an Android Service that runs in the background and checks for internet connectivity regularly. As soon as the internet is connected, it can start the Cloud Firestore sync.
Do not use Realtime Database for this. Use Cloud Firestore which is way better.

Related

Can a Firebase Realtime Database persist data on web like Cloud Firestore? [duplicate]

This question already has an answer here:
Does Firebase JavaScript API catch-up with server when re-connected
(1 answer)
Closed last year.
I have a web app that uses a Realtime Database to store data. If I go offline while the database is connected, make changes, and reconnect, everything works as intended. However, I'm trying to make my web app work as a PWA. Right now, the database only works offline if the page goes online while being used. If you close the app fully while offline and open the app, it won't load.
I see that Cloud Firestore for web has the enableIndexedDbPersistence() method, which appears to do what I want, although obviously since it's for a different service I can't use it. I also see that Realtime Database for Android has FirebaseDatabase.getInstance().setPersistenceEnabled(true), but since its for Android I can't use it for a web app.
Is there a way to enable this functionality?
Firebase Realtime Database only supports disk persistence in its Android and iOS SDKs. There is no disk persistence in the JavaScript SDK for Firebase Realtime Database.
Also see:
Does Firebase JavaScript API catch-up with server when re-connected

Firebase database & local storage

Our iOS app uses CoreData as the local datastore and we use Firebase to sync the local data across devices. We also rely on FireBase for user authentication, so its just not the data sync. All our queries are done against the local database. This 'local db + Firebase' combination has worked well so far and we are starting to build the Android version.
With the new brand new Android code, we are debating if we should follow the same approach as iOS or just use ONLY the Firebase database.
Some features that are important to our app:
Work completely offline (Firebase does a great job of syncing when there is online access)
Have a single cloud database as the source of truth i.e. mimicking a server side database
Reduce network usage, i.e. use it only when required
Be able to perform a variety of queries on the data
Real time data across devices (Firebase realtime sync is awesome )
Any disadvantages to our existing approach 'local db + Firebase' or what will we lose if we switch to using just the Firebase Database ?
FireBase just released FireStore which was built from the ground up to also support offline mode. Looking forward to test this

Persisting state of Firebase data [duplicate]

I have built an application with Firebase and I've also made a desktop version available with nw.js. The point of this being to allow for better offline usage in areas with bad or no internet (and it will sync when the user gets internet again). Now, I can disconnect just fine and reconnect while the app is running, but I want to be able to fully close and reload the application. I've seen this blog post from firebase, but it appears this only works for mobile platforms.
Is this currently possible on the web platform, too?
All Firebase SDKs will handle intermittent loss of connectivity (driving through a tunnel). But disk based persistence, which allows the data to survive an app restart, is currently only available in Firebase's iOS and Android SDKs.

Ionic/Firebase store data local and sync [duplicate]

I have built an application with Firebase and I've also made a desktop version available with nw.js. The point of this being to allow for better offline usage in areas with bad or no internet (and it will sync when the user gets internet again). Now, I can disconnect just fine and reconnect while the app is running, but I want to be able to fully close and reload the application. I've seen this blog post from firebase, but it appears this only works for mobile platforms.
Is this currently possible on the web platform, too?
All Firebase SDKs will handle intermittent loss of connectivity (driving through a tunnel). But disk based persistence, which allows the data to survive an app restart, is currently only available in Firebase's iOS and Android SDKs.

Persist data with firebase web

I have built an application with Firebase and I've also made a desktop version available with nw.js. The point of this being to allow for better offline usage in areas with bad or no internet (and it will sync when the user gets internet again). Now, I can disconnect just fine and reconnect while the app is running, but I want to be able to fully close and reload the application. I've seen this blog post from firebase, but it appears this only works for mobile platforms.
Is this currently possible on the web platform, too?
All Firebase SDKs will handle intermittent loss of connectivity (driving through a tunnel). But disk based persistence, which allows the data to survive an app restart, is currently only available in Firebase's iOS and Android SDKs.

Resources