How to check whether there is internet connection with the device: cocos-2d
Asked Answered
C

1

9

In one of my iPhone app, I need to find out whether there is internet connection with the device or not. Anyone pls help?

Cataclysmic answered 18/1, 2013 at 10:34 Comment(0)
R
8

Use Reachability class.

  if([self checkInternetConnected] ) 
  {
    NSLog(@"Internet connected\n");
  } 


- (BOOL)checkInternetConnected 
{
    Reachability *reachability = [Reachability reachabilityForInternetConnection];  
    NetworkStatus networkStatus = [reachability currentReachabilityStatus]; 
    return !(networkStatus == NotReachable);
}

You can get rechability class here : Download sample and add Reachability.h and Reachability.m into your project.

Rybinsk answered 18/1, 2013 at 13:21 Comment(1)
And then you must add: SystemConfiguration.framework if you haven't added it yet! Good luckCretin

© 2022 - 2024 — McMap. All rights reserved.