你好,
我想要检查飞行模式是否开启,如何检查?
谢谢。另外,如何检查用户正在使用 WIFI、GPRS 还是 EDGE 并进行区分?
你好,
我想要检查飞行模式是否开启,如何检查?
谢谢。另外,如何检查用户正在使用 WIFI、GPRS 还是 EDGE 并进行区分?
如果你只是想在用户处于飞行模式时显示通知,那么启用应用程序的属性文件中的SBUsesNetwork属性就足够了。当你的代码使用网络时,系统会自动提示用户关闭飞行模式。
请参见这篇文章。
针对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;
}
这回答了问题的第二部分 - 如何判断用户所在的网络类型(Wifi还是3g/edge)。它使用了苹果公司的Reachability代码。将以下代码放入您的应用委托中的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;
}
}
我不确定你是否可以专门检查飞行模式,但 iPhone ADC 网站上的 reachability 示例可以让你检查 iPhone 是否能够访问互联网。