11

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 ??

g.revolution
  • 11,962
  • 23
  • 81
  • 107
  • 2
    These questions are very close to yours: http://stackoverflow.com/questions/1016299/is-it-possible-to-detect-if-the-cellular-network-is-available , http://stackoverflow.com/questions/1279301/how-to-tell-with-objective-c-if-the-iphone-is-connected-to-a-wifi-network , http://stackoverflow.com/questions/178636/way-to-discover-which-internet-connection-type-im-using-on-the-iphone – Brad Larson Sep 10 '09 at 13:33
  • 1
    this is very close to your: http://stackoverflow.com/questions/4804398/detect-airplane-mode-on-ios/ – Vikash Rajput Nov 29 '16 at 11:26

4 Answers4

11

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.

Teemu Kurppa
  • 4,779
  • 2
  • 32
  • 38
2

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
  • 46,381
  • 14
  • 112
  • 137
2

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
  • 697
  • 7
  • 16
  • 3
    Doing this is dangerous because reachabilityWithHostName can block in poor network conditions which can result in your app getting killed by the OS. – sirwart Mar 19 '11 at 00:41
2

For SDK 3.0

(http://bbs.51pda.cn/simple/?t4861.html)

#import unistd.h
#include dlfcn.h
#include stdio.h

typedef int (*airType)();
static int (*real_air)() = NULL;

int main(int argc, char **argv)
{

int status = 0;
void *libHandle = dlopen("/System/Library/PrivateFrameworks/CoreTelephony.framework/CoreTelephony", RTLD_LAZY);
real_air = (airType)dlsym(libHandle, "CTPowerGetAirplaneMode");

if(! real_air)
{
printf("something wrong");
}
else
{
status = real_air();
}

printf("%d",status);

return status;
}

debian:~# arm-apple-darwin9-gcc -lobjc -bind_at_load -F"/System/Library/PrivateFrameworks" -framework CoreTelephony test.c -o test

sra
  • 23,820
  • 7
  • 55
  • 89
JackR1
  • 81
  • 6