【问题标题】:iphone how to check the Airplane mode?iphone如何查看飞行模式?
【发布时间】:2010-11-27 03:22:08
【问题描述】:

你好,

我想检查飞行模式是否打开..如何检查?

谢谢 + 如何检查用户正在使用 WIFI 或 GPRS 或 EDGE。怎么区分??

【问题讨论】:

标签: iphone airplane


【解决方案1】:

如果您只想在用户处于飞行模式时显示通知,那么在应用的 plist 文件中启用 SBUsesNetwork 属性就足够了。当您的代码使用网络时,系统会提示用户自动关闭飞行模式。

参见例如this post.

【讨论】:

  • 只执行一次。您运行应用程序,警报就会出现,...之后您将不会收到提示...
  • 你确定 SBUsesNetwork 没有被弃用吗?似乎 Apple 在其文档中的任何地方都没有提及它......
  • 答案中的链接已失效 - 404 Not Found
【解决方案2】:

我不确定您是否可以专门检查飞行模式,但 iphone adc 网站上的 reachability 示例可让您检查 iphone 是否可以访问互联网。

【讨论】:

  • 它不会告诉你飞行模式是打开还是关闭。
【解决方案3】:

这回答了问题的第二部分 - 如何判断用户使用的网络类型(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;
    }
}   

【讨论】:

  • 这样做很危险,因为reachabilityWithHostName 会在网络状况不佳的情况下阻塞,从而导致您的应用被操作系统杀死。
【解决方案4】:

对于 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-09
    • 1970-01-01
    • 2016-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-03
    相关资源
    最近更新 更多