AFNetworking and No Internet Connection scenario
As of 0.9, AFHTTPClient
actually has network reachability built-in (a simpler interface to Apple's aforementioned Reachability code). Just include the SystemConfiguration
framework and use -setReachabilityStatusChangeBlock:
to specify a response when the reachability state changes.
With AFNetworking
these are the steps that one has to follow in order to take advantage of setReachabilityStatusChangeBlock:
after adding the AFNetworing classes -
- Add
SystemConfiguration.framework
to your project - In pch file add
#import <SystemConfiguration/SystemConfiguration.h>
- Assuming that you have a subclass of
AFHTTPClient
in this subclass add below lines of code in init function -
[self setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { NSLog(@"changed %d", status); //your code here }];
Maybe you could use "Reachability" to determine if the device is connected to the network.Here is the link to the Apple Doc. : Reachability
For example :
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNetworkChange:) name:kReachabilityChangedNotification object:nil];reachability = [Reachability reachabilityForInternetConnection];[reachability startNotifier];NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];if(remoteHostStatus == NotReachable) { //Your UIAlertView}