Tuesday, 4 June 2013

How to check whether there is internet connection with the device: cocos2d/Xcode

You can check whether there is internet connection with the device/not with the help of following code:

     // in .h File //

        Import Reachability class.
       


    // in .m File //

        if([self connected] )
        {
            NSLog(@"Internet connected\n");
        }
       
        - (BOOL)connected
        {
            Reachability *reachability = [Reachability reachabilityForInternetConnection];
            NetworkStatus networkStatus = [reachability currentReachabilityStatus];
            return !(networkStatus == NotReachable);
        }

No comments:

Post a Comment