What i have done for my case was, i have put below snippet in the didFinishLaunchingWithOptions
// Instantiate Shared Manager
[AFNetworkReachabilityManager sharedManager];
// Start network networking monitoring
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
NSLog(@"Reachability: %@", AFStringFromNetworkReachabilityStatus(status));
if ([[AFNetworkReachabilityManager sharedManager] isReachable]) {
NSLog(@"IS REACHABILE");
//Here check if your network connection view is already showing on screen, if positive then remove it
if (_viewNetworkConnectionCheck) {
//[_viewNetworkConnectionCheck removeFromSuperView];
_viewNetworkConnectionCheck = nil;
}
} else {
NSLog(@"NOT REACHABLE");
//You have to add your network connectivity view here, just make sure if has been has not been allowcated
if (!_viewNetworkConnectionCheck) {
//[[UIApplication sharedApplication].keyWindow addSubview:_viewNetworkConnectionCheck];
}
}
}];
Also if you have to call web service every time app goes from background state to foreground state then what you can do is (or what i have done was) put below snippet in the delegate applicationWillEnterForeground
[self performSelector:@selector(callWebserviceToRefreshData) withObject:nil afterDelay:0.5f];
and add this method to call web service after checking internet connectivity safely
-(void)callWebserviceToRefreshData {
if ([JeebleyHelper isConnected]) {
NSLog(@"Yes, network available");
//Call your web service here
} else {
NSLog(@"No, network not available");
}
}
Just make sure you call your dataRefresh method after some time delay, otherwise isConnected will always give you the previous state.
+ (BOOL)isConnected {
return [AFNetworkReachabilityManager sharedManager].reachable;
}