你好 ,
我想检查飞行模式是否打开..如何检查?
谢谢 + 如何检查用户是否使用 WIFI 或 GPRS 或 EDGE。怎么区分??
如果您只想在用户处于飞行模式时显示通知,那么在应用程序的 plist 文件中启用 SBUsesNetwork 属性就足够了。当您的代码使用网络时,系统会提示用户自动关闭飞行模式。
参见例如这篇文章。
我不确定您是否可以专门检查飞行模式,但 iphone adc 网站上的可达性示例使您能够检查 iphone 是否可以访问互联网。
这回答了问题的第二部分 - 如何判断用户使用的网络类型(Wifi 或 3g/edge)。它使用 Apple 的可达性代码。把它放在你的应用委托中的 didFinishLaunchingWithOptions 方法中:
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;
}
}
对于 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