简体   繁体   中英

iphone - how do i check whether im connected to a wifi network

i read,seen the Reachablility example in Apple's website but still not quite sure about determining whether the iphone is connected to a wifi network/ or a pc(ipaddress). All i understand about that example is that you give it a address, and it checks how it is accessible either via wifi,WWAN or not reachable at all.

Could anyone shed some light on this? Im new to iPhone programming :\\

What i want is to check whether the iPhone is connected to a particular ipaddress via wifi at that moment of time, like clicking a button and a UIAlertView shows "Not connected via wifi to "INSERT IPADDRESS HERE" "when its not connected. Am i making sense? lol.

The IP address is just used for testing a connection through wi-fi or WWAN to another machine on the Internet. All the Reachability framework tells you is if your device is connected to a TCP/IP network via wi-fi networking, via WWAN (through your cell phone connection), or not connected at all. It does not tell you if your phone is connected to a Mac or PC through the dock connector cable.

the reachability sample is strange, check this out

-(BOOL)hasWifiConnectivity{
    SCNetworkReachabilityRef reachabilityRef = SCNetworkReachabilityCreateWithName(NULL,"apple.com");
    SCNetworkReachabilityFlags flags;
    if (SCNetworkReachabilityGetFlags(reachabilityRef,&flags)) {
        CFRelease(reachabilityRef);     
        if (flags & kSCNetworkReachabilityFlagsReachable) {
            if (flags & kSCNetworkReachabilityFlagsIsWWAN) {    
                //not wifi
                return NO;
            }else {
                //wifi
                return YES;
            }
        }
    }   
    return NO;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM