I need to check if the user is connected to wifi or not. If the user is connected to mobile internet i want a alert message to say something like "for best performance, you should be connected to wifi" How can i do this in Objective-C?
Asked
Active
Viewed 1,369 times
1
-
Look into the Reachability classes http://stackoverflow.com/questions/1083701/how-to-check-for-an-active-internet-connection-on-iphone-sdk/7934636#7934636 – thelaws Jun 16 '14 at 20:58
1 Answers
2
Oops, sorry I didn't realize you wanted Wifi. For that case, reachability is your friend.
- (void)checkForWIFIConnection
{
Reachability* wifiReach = [Reachability reachabilityForInternetConnection];
NetworkStatus netStatus = [wifiReach currentReachabilityStatus];
if (netStatus != ReachableViaWiFi)// ReachableViaWWAN == 3G, ReachableViaWiFi == WIFI
{
NSString *message = [[NSString alloc] initWithFormat:NSLocalizedString(@"InitialNoWifiMessage", nil)];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"InitialNoWifiTitle", nil)
message:message
delegate:self
cancelButtonTitle:NSLocalizedString(@"InitialNoWifiAccept", nil)
otherButtonTitles:nil];
[alertView show];
}
else
{
// connected to Wifi
}
}

TooManyEduardos
- 4,206
- 7
- 35
- 66
-
This will only determine whether the network is connected, not if it's a wifi or 3G/LTE connection. – thelaws Jun 16 '14 at 20:58
-
-
Do I need to import something? I get error message that Reachability is not a valid code. – Freddy Jun 16 '14 at 21:10
-
Yeah you need to add the Reachability.h and Reachibility.m to your project (you can get them from apple here:https://developer.apple.com/Library/ios/samplecode/Reachability/Listings/Reachability_Reachability_m.html#//apple_ref/doc/uid/DTS40007324-Reachability_Reachability_m-DontLinkElementID_8) and then in the class that you'll use the code do #import "Reachability.h" – TooManyEduardos Jun 16 '14 at 21:13
-