The only solution I found online was for Android- not for Unity- by listening to ('.info/connected')
like here- Detect if Firebase connection is lost/regained.
But I tried it and it doesn't work (tried to translate their Android solution to C#)-
DatabaseReference connectedRef = FirebaseDatabase.DefaultInstance.GetReference(".info/connected");
connectedRef.ValueChanged += (object sender, ValueChangedEventArgs a) => {
bool isConnected = (bool)a.Snapshot.Value;
print("isConnected" + isConnected);
};
When I try my code:
Test #1:
Connected to the internet- starting the app
log-
isConnected = true
- disconnect from the internet
- a lot of socket errors, no calls to isConnected anymore (still true)
Test #2:
Disconnected to the internet- starting the app
log-
isConnected = false
- a lot of socket errors
- Connect to the internet
- log-
isConnected = true
Which means= listeners don't work on offline mode
and the reason why I get isConnected = false
only on test #2 is because the function is being called once on start...
How can I tell when the user isn't connected? It's important because I have to manage everything manually until the user is online again- to update the database.