开发者

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

开发者 https://www.devze.com 2023-01-08 01:50 出处:网络
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

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 开发者_JAVA百科:\

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消