Friday, February 17, 2017

Firebase - Offline Capabilities

In this chapter we will show you how to handle Firebase connection state.

Check Connection

We can check for connection value using the following code.

index.js

var connectedRef = firebase.database().ref(".info/connected");

connectedRef.on("value", function(snap) {
   if (snap.val() === true) {
      alert("connected");
   } else {
      alert("not connected");
   }
});
When we run the app, the pop up will inform us about the connection.
Firebase Offline Popup By using the function above you can keep track of connection state and update your app accordingly.

No comments:

Post a Comment