Search code examples
iosios5afnetworkingafnetworking-2

How to check whether host(server) is available or not in iOS with AFNetworking


I am using AFNetworking in my App for communicating with server. How can i check whether my host(server) is available or not, i should check this before i am sending a request to server.


Solution

  • Using AFNetworking 2.0 that provide method like below you can check instead of using Reachability class.

    - (void)viewDidLoad {
       [super viewDidLoad];
    
        [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    
    }
    

    After set start-monitoring in to viewDidLoad you can check any where in to class using Bellow Method.

     if ([[AFNetworkReachabilityManager sharedManager] isReachable]) 
     {
       NSLog(@"IS REACHABILE");
     } 
     else 
     {
       NSLog(@"NOT REACHABLE");
     }