I'm trying to listen to Firebase's callback -
let ref = Database.database().reference()
ref.child(key).observe(.value) { (snapshot) in
print("snapshot")
}
this method getting called every time I update some value inside the given key
node.
Unfortunately, it's not getting called while the application is in the background. I know about background fetch but I don't want to fetch I want to wait for the callback, which will come, sometimes after 1 minute other times after 10 minutes (with background fetch I need to wait for the OS to decide that now it's a good time to make the fetch)
How can I stay alive in the background to listen to firebase callbacks?
EDITED:
I will explain more about my use case - I need to send the user a local notification every time the database node changes. but the listener is not called while the app is in the background so I can't invoke a local notification.
I know I can use push notifications but I don't want to make these changes to my database, I currently don't need users or device ID or anything like that, and I would like to keep it this way.
Edited
More about the use case -
I have 4 players in a long turn-based game.
While player 1 plays, player 4 will probably not stay in the app because it can take some time (from 1 - 30 minutes).
I want to notify player 4 when it is his turn.
Each player sets a turn
value every time he finishes his turn and the other players are listening to changes in that value.
On android, we just keep listening to these changes all the time even in the background, and when turn
changes, the listeners get the callback, and from that callback, we notify the user "it's your turn" via local notification. I would like to do the same on iOS.