You can do something like this. Setup the observer and post notification on status change. Basically the same as accepted answer but adapted to new version of firebase framework.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
FIRDatabaseReference *ref = [[FIRDatabase database] referenceWithPath:@".info/connected"];
[ref observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
NSString *value = snapshot.value;
NSLog(@"Firebase connectivity status: %@", value);
self.firebaseConnected = value.boolValue;
[[NSNotificationCenter defaultCenter] postNotificationName:@".fireBaseConnectionStatus" object:nil];
}];
}
Then in any view controller of your app you can do this. Observe notifications and do something based on that (update your ui, etc).
- (void) fireBaseConnectionStatus:(NSNotification *)note
{
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[self updateButtons:app.firebaseConnected];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fireBaseConnectionStatus:) name:@".fireBaseConnectionStatus" object:nil];
}
Hope this will help.
PS. Perhaps you will find it interesting idea to also monitor basic reachability with well known reachability.[mh] framework. Then you also could decide how do you act in case that firebase is connected on wifi or 3g.