views:

818

answers:

3

HI ,

i want to check wether Airplane mode is on or not .. how to check that ?

thanks + how to check that the user is using WIFI or GPRS OR EDGE . how to differentiate ??

+2  A: 

I'm not sure if you can check specifically for airplane mode but the reachability example from the iphone adc website enables you to check if the iphone has access to the internet.

ennuikiller
it does'nt tell you that whether the airplane mode in on or off.
g.revolution
+3  A: 

If you just want show notification, when user is in airplane mode, then it's enough to enable SBUsesNetwork property in your app's plist file. When your code is using network, user is prompted to turn off Airplane mode automatically.

See e.g. this post.

tequilatango
it is done only one time. you run the application the alert will come , ... after that you will not get the prompt ...
g.revolution
Are you sure SBUsesNetwork isn't deprecated or something? It seems Apple doesn't mention it even once anywhere in their documentation...
Psionides
A: 

This answers the second part of the question - how to tell what type of network the user is on (Wifi or 3g/edge). It uses the Reachability code from Apple. Put this in your didFinishLaunchingWithOptions method in your app delegate:

Reachability *curReach = [Reachability reachabilityWithHostName: @"www.apple.com"];
NetworkStatus netStatus = [curReach currentReachabilityStatus];
switch (netStatus)
{
    case NotReachable:
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Network Status" message:@"Please note: Network access is required to retrieve images." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [alert show];
        [alert release];
        break;
    }
    case ReachableViaWiFi:
    case ReachableViaWWAN:
    {
        break;
    }
}   
dnstevenson