Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Network check for wifi 3g 4g

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 209
    Comment on it

    Hi Guys,

    You can use this function before hitting any server api. This will check whether your device is connected to network or not.

    + (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) {
            [self showAlertMessage:ALERT_NETWORK_ERROR];
        }
        return _isDataSourceAvailable;
    }
    

    Thanks

 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: