Firebase observer not working, why won't it keep a watch on the value change?

Famic Tech

I am trying to set a Firebase observer by calling the following:

ref.child(id).child("isLocked").observe(.value, with: { snapshot in

    print("isLocked = ", snapshot.value!)

})

When the view loads it works perfectly. It prints out the correct value.

When I go change the value either in Firebase itself or on a separate device the isLocked is never printed again. When it should be since I have an observer on the path. What gives?

The end goal here is to have a UIButton available based on if the lock value is true of false.

The view is loaded with the button.isHidden = true.

UPDATE

I found the source of my issue with observer not "Working"

It would seem that there is a timing issue.

In the previous view controller (which segues into the new view controller) I am calling ref.child(pID).child("isLocked").removeAllObservers() in the 'viewDidDisappear' function

And in the new view controller I am 'trying' to setup the same path observer 'ref.child(id).child("isLocked").observe(.value, with: { snapshot in'

which I guess the removeAllObservers() trumps the setup of the new observer!? How do I get over this!?

Famic Tech

I found the source of my issue with observer not "Working"

It would seem that there is a timing issue.

In the previous view controller (which segues into the new view controller) I am calling ref.child(pID).child("isLocked").removeAllObservers() in the viewDidDisappear function

And in the new view controller I am 'trying' to setup the same 'path observer' ref.child(id).child("isLocked").observe(.value, with: { snapshot in.

Which I guess the removeAllObservers() trumps the setup of the new observer!?

To remedy this you need to setup specific handles per observer! Make sure to use unique var names and no reuse and then call the following instead of removeAllObservers():

ref.child(id).child("isLocked").removeObserver(withHandle: confirmVCRefHandle!)

the above handle name confirmVCRefHandle is unique and the timing issue is overcome!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Firebase: is there any observer to watch for change in email verification status?

Firebase fetch data using .value observer is not working?

Why Won't This Firebase Callable Function Return A Value?

Remove observer after value change in Firebase

Why won't the value of char* change when I assign it in a function?

Why won't my bool variable change its value

why useObserver hook won't rerender twice, comparing to observer hoc?

My onclick function isn't working because the function won't change the boolean value

Why isn't webpack watch working?

Firebase won't trigger data change event

Change reactive expression, keep observer

Why won't text in tkinter change?

Why won't the border radius change?

function won't change value of variable in java?

JScrollBar thumb position (value) won't change

Why won't PHP print 0 value?

Why won't this code permute the value Z?

Why won't the last array value be returned?

Why won't my Redux change state change at all?

Why is a observer class not working in model?

Observer won't run update in JavaFX GUI

Why is this code not working correctly? Won't take the elif statements

Why won't my Strings from Firebase show on myRecyclerView

Why my Firebase addvalueEventlistener won't get called?

Creating StreamBuilder to keep track whenever there is a change on Sensor value with Realtime Firebase

Why isn't my firebase config working?

Why won't the state change in a unit test for an AngularJS controller?

Why won't my JPanel background color change?

Why won't my UI reflect a change in the @State property?