Observers Hanging While Using Firebase Offline

I'm trying to add standalone features to our iOS app (just add an app that manages users and projects) that relies on Firebase. It uses Swift 3.0. I followed the instructions and did the following:

  • Added this to his application delegate right after FIRApp.configure ():

    FIRDatabase.database (). persistenceEnabled = true

  • called keepSynced (true) for users / userKey and all specified user projects / ProjectKey nodes.

The application works fine online (obviously) and works equally well offline even if I restart it when it is disconnected from the Internet. The problem occurs when I create a new project offline. To create a new project, I use the following:

let projectKey = FIRDatabase.database().reference(withPath: "projects").childByAutoId().key let logsKey = FIRDatabase.database().reference(withPath: "projects").child(projectKey).child("logs").childByAutoId().key FIRDatabase.database().reference().updateChildValues([ "projects/\(projectKey)/key1" : value1, "projects/\(projectKey)/key2" : [ "subkey1" : subvalue1, "subkey2" : subvalue2 ], "projects/\(projectKey)/key3/\(logKey)" : [ "subkey3" : subvalue3, "subkey4" : subvalue4 ] ]) { error, ref in if error != nil { print("Error") return } } 

After creating the project, if I try to call watchSingleEvent on "projects / projectKey / key1" or "projects / projectKey / key2", everything will be fine. However, calling the same function on "projects / projectKey / key3 / logKey" never starts a block / callback - it is called only when the connection returns.

I turned on FIRDatabase logging (which confirms the local record) to look for clues, but cannot figure out what the problem is.

Is there something I am missing?

Note. Using the latest version of Firebase iOS SDK (3.5.2).

EDIT: It seems to work fine if I expand the deep links:

 let projectKey = FIRDatabase.database().reference(withPath: "projects").childByAutoId().key let logsKey = FIRDatabase.database().reference(withPath: "projects").child(projectKey).child("logs").childByAutoId().key FIRDatabase.database().reference().updateChildValues([ "projects/\(projectKey)" : [ "key1" : value1, "key2" : [ "subkey1" : subvalue1, "subkey2" : subvalue2 ], "key3" : [ logKey : [ "subkey3" : subvalue3, "subkey4" : subvalue4 ] ] ] ]) { error, ref in if error != nil { print("Error") return } } 

Could this be a mistake in the way that Firebase manages its local cache states offline? It was as if he did not know about the intermediate keys created using deep links in updateChildValues.

+5
source share

All Articles