Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To check if wifi option enabled or not

How to check if wifi option is enabled on the iPhone or not (but maybe iPhone not connected to one of the wifi net).

like image 490
Oksana Avatar asked Nov 02 '11 04:11

Oksana


1 Answers

For this you need to import reachability classes in your project.

After then:-

#import "Reachability.h"

In you view DidLoad write:-

- (void)viewDidLoad {
    Reachability *internetReach = [[Reachability reachabilityForInternetConnection] retain];
    [internetReach startNotifer];
    Reachability *wifiReach = [[Reachability reachabilityForLocalWiFi] retain];
    [wifiReach startNotifer];

    NetworkStatus netStatus1 = [internetReach currentReachabilityStatus];
    NetworkStatus netStatus2 = [wifiReach currentReachabilityStatus];
    if(netStatus1 == NotReachable && netStatus2 == NotReachable)
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"This feature requires an internet connection." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
        [alertView release];
    }
    else
    {//wifi connection available;
}
}
like image 101
Gypsa Avatar answered Oct 22 '22 22:10

Gypsa