Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Check Wifi Network reachability in Swift

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 877
    Comment on it

    In Swift if you want to check the Wifi connection in your device then use following code.

    This is a function which returns Reachability instance (reachability class object) value as a returnvalue for wifi connection availability.

    + (instancetype)reachabilityForLocalWiFi
    {
        struct sockaddr_in localWifiAddress;
        bzero(&localWifiAddress, sizeof(localWifiAddress));
        localWifiAddress.sin_len = sizeof(localWifiAddress);
        localWifiAddress.sin_family = AF_INET;
    
        // IN_LINKLOCALNETNUM is defined in  as 169.254.0.0.
        localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM);
    
        Reachability* returnValue = [self reachabilityWithAddress: &localWifiAddress];
        if (returnValue != NULL)
        {
            returnValue->_alwaysReturnLocalWiFiStatus = YES;
        }
    
        return returnValue;
    }
    

    Hope this will help you. Happy Coding!!!

 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: