2

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:

  1. Can I some how automatically send data to server without user opening the app when the internet connectivity is established?

  2. 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?

2
  • firebase docs Commented Aug 28, 2019 at 9:23
  • The doc refers to offline capabilities for detecting and managing tasks when user goes offline and comes online. It does not say anything about data persistence when user kills mobile application. Commented Sep 3, 2019 at 8:02

2 Answers 2

1

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.

  1. 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.
  2. Do not use Realtime Database for this. Use Cloud Firestore which is way better.
Sign up to request clarification or add additional context in comments.

3 Comments

Do react-native-firebase's Cloud Firestore api's support offline persistence using react-native without writing native java code? I see react-native-firebase's realtime database api only support offline persistence using native code. rnfirebase.io/docs/v4.0.x/core/…
Yes it does. It's enabled by default.
@thecodrr can you please provide any example where this local data gets synced when user comes online and even if user performs something on app while offline and kills the app . This data is also needs to be pushed to firebase. Do you have any links/example where this scenario works ?
0

I have no personal experience persisting data while offline as I'm looking for a similar solution. However, it would appear that the react-native-firebase supports persistence in the realtime firebase with this addition to the root firebase.json file

// <project-root>/firebase.json
{
  "react-native": {
    "database_persistence_enabled": true
  }
}

See https://rnfirebase.io/database/usage#enabling-persistence
and https://rnfirebase.io/database/offline-support

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.