1

I have a situation in which my Firebase reference is not invoking the callback for observeSingleEvent.

 let uid = FIRAuth.auth()?.currentUser?.uid

 FIRDatabase.database().reference().child("users").child(uid).observeSingleEvent(of: .value, with: { (snapShot) in                    
           //code here not called
        }) { (error) in
           //code here not called either
        }

In my case it appears the uid property which is coming from FIRAuth.auth()?.currentUser?.uid is somehow being cached from a previous app installation when I'm switching between Firebase environments (building with different dev and staging .plist files.)

However, if I just add a random non existing string in place of uid the callback occurs as expected with an empty snapshot for a missing reference node.

I believe it's relevant to mention that I'm using synced Firebase references with persistanceEnabled = true.

I'm in a situation where I'm switching between environments and my app is hanging because promises are not being fulfilled or rejected because the results of by observeSingleEvent method call are never completing.

AL.
  • 36,815
  • 10
  • 142
  • 281
nwales
  • 3,521
  • 2
  • 25
  • 47
  • And I can confirm that the uid value is always a non nil uid-looking string – nwales Dec 22 '16 at 03:45
  • 1
    Since you've been using disk persistence, most likely there is an outdated value in the cache. The best way to not be affected by this caching behavior is to use a regular observer, disk persistence and `observeSingleEvent` don't mix well. See my explanation here (for Android, but the iOS client works the same way): http://stackoverflow.com/questions/34486417/firebase-offline-capabilities-and-addlistenerforsinglevalueevent/34487195#34487195 – Frank van Puffelen Dec 22 '16 at 03:50
  • so, even switching to observe vs observeSingleEvent is still never firing that block of code. Same behavior as above. Should I expect the callback to call even if it's running against an outdated cache? – nwales Dec 22 '16 at 16:35
  • Attaching a listener to a location will synchronize the data for that location and thus update the persistent cache for that location. – Frank van Puffelen Dec 23 '16 at 04:31
  • @FrankvanPuffelen are you saying that even if I have a FirebaseReference instance that I call keepSynced(true) meathod on, it still won't synchronize unless there is an actual listener on that reference? – nwales Dec 23 '16 at 19:26
  • Calling `keepSynced(true)` puts an invisible listener on that location. So the result will be the same: your cache will be kept up to date. – Frank van Puffelen Dec 23 '16 at 23:45

0 Answers0