React-native-firebase: Realtime Database Offline Persistence Behaviour Unexpected

Created on 21 Apr 2018  路  4Comments  路  Source: invertase/react-native-firebase

Targeted: iOS, developed on macOS
react-native-firebase: 4.0.4
react native: 0.54.2

So, I find that I can't retrieve data once the app is offline and gets restarted.

_Reproducing:_

Where I retrieve the dataset

import firebase from 'react-native-firebase'

export const sync = () => {

  let start = new Date()
  console.log('sync', start)
  const productsRef = firebase.database().ref('test')

  productsRef.keepSynced(true);

  productsRef.on('value', snap => {
    console.log(snap)
    console.log('done!', (new Date()-start)/1000)
  })
}

It works when sync() is used online, and the device then goes offline. The data are still retrievable. Even using CMD+R to refresh doesn't do harm.

However, then if I turn off WiFi, kill the app in the background and restart the app, sync() won't give any result unless turning on WiFi.

Actually, I am describing something as in the official document: https://firebase.google.com/docs/database/ios/offline-capabilities#section-disk-persistence

Is it not supported yet, or do I need specific configuration (which I didn't find anywhere) ?

User Issue Database Docs Question

Most helpful comment

@xyzzyxyzzy0077 https://rnfirebase.io/docs/v4.0.x/core/default-app#Enable-Database-Persistence also here - probably not the best place for it though on the docs

All 4 comments

Worked it out

For anybody encountering with this problem, you need to enable database offline persistence in Xcode or Android counterpart. Offline persistence setting is no longer supported using JS, as seen here

Which is so critical and totally deserves to be specified in the doc. Let alone the facts that I'm always using v3.0+, having no idea what is used to be; and Firestore's offline persistence is enabled by default, making people think realtime database should be as so, however, in fact it is not.

Hope nobody would again need 7+ hours to find the answer.

Cheers.

@xyzzyxyzzy0077 https://rnfirebase.io/docs/v4.0.x/core/default-app#Enable-Database-Persistence also here - probably not the best place for it though on the docs

Thanks! It is a lot of work making this stuff for fun and putting in the time tho.. Going to take a look!

Thanks devs! here is a huge chocolate to say thanks! :hugeChocolate

Was this page helpful?
0 / 5 - 0 ratings