0

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.

SHAI
  • 789
  • 3
  • 10
  • 43
  • What's the problem with the code you shared? What does it print when you're online? And what when you are/go offline? – Frank van Puffelen Dec 25 '18 at 07:09
  • I added new information to my question – SHAI Dec 25 '18 at 20:57
  • Hmmm... the results of test #1 seem unexpected. After a while, the value of `.info/connected` should become `false` in this case. I hope somebody else sees what could be causing this. – Frank van Puffelen Dec 26 '18 at 05:44
  • 1
    It's because the listeners don't work/call the function when offline mode so it stays true, But for example- on test #1 if I force and call that function Manually - it'll show me that isConnected=false – SHAI Dec 26 '18 at 17:59

0 Answers0