Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Check for Internet Connection

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 210
    Comment on it

    Hi All

    To check internet connection using objective c you can use this function.

    There may be a plethora of reasons that you need to check whether or not the device that is using your application has an internet connection. If checking whether the device is somehow connected to the internet is everything you want to do, Just call this function and if it is connected it will return true otherwise false


    + (BOOL)isNetworkAvailble{
        const char *host_name = "google.com";
        BOOL _isDataSourceAvailable = NO;
        Boolean success;
    
        //Creates a reachability reference to the specified
        //network host or node name.
        SCNetworkReachabilityRef reachability =
        SCNetworkReachabilityCreateWithName(NULL,host_name);
    
        //Determines if the specified network target is reachable
        //using the current network configuration.
        SCNetworkReachabilityFlags flags;
    
        success = SCNetworkReachabilityGetFlags(reachability, &flags);
        _isDataSourceAvailable = success &&
        (flags & kSCNetworkFlagsReachable) &&
        !(flags & kSCNetworkFlagsConnectionRequired);
    
        CFRelease(reachability);
        if (!_isDataSourceAvailable) {
            NSLog(@"No internet connection");
        }
        return _isDataSourceAvailable;
    }
    

    It return true i device have internet connection

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: