Reputation: 25
I am working on a mobile game, where I would like to know if the player has internet connection or not. I tried doing it with the following methods:
Is there a way I can achieve what I want with Firebase?
Please note that if the player has no internet connection, they should not be able to click on any of the game functions, because it will cause bugs, so I would like to check for connection continuously. When there is no connection I disable the GUI so that the player can not cause bugs)
Upvotes: 0
Views: 1088
Reputation: 598901
If you're using the Firebase Realtime Database, it has a built-in mechanism to show you when the app is connected to the database servers. By listening to the .info/connected
node, you can detect this state and update your UI.
Note that this is not just detecting an internet connection, but whether the app is connected to the database backend. So in cases where the user may have an internet connection, but can't connect to the database backend, the flag may be false.
Upvotes: 2