tags:

views:

158

answers:

2

hi guys, 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.

A: 

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.

Alex Reynolds
ok cool. so what methods should i look out for in the Reachablitity example if i want to check whether the iPhone has its wifi connected to a particular address?
Kenneth
Look at `+reachabilityForLocalWiFi` among others. You'll find this in the `Reachability.h` header file: http://developer.apple.com/iphone/library/samplecode/Reachability/Listings/Classes_Reachability_h.html#//apple_ref/doc/uid/DTS40007324-Classes_Reachability_h-DontLinkElementID_5
Alex Reynolds
ok cool, i'll give it a try.
Kenneth
+1  A: 

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