iPhone如何查看飞行模式?

发布于 08-04 19:33 字数 89 浏览 14 评论 0原文

你好,

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

苏大泽ㄣ2024-08-11 19:33:17

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

请参阅这篇文章

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.

深者入戏2024-08-11 19:33:17

我不确定您是否可以专门检查飞行模式,但是 可达性 来自 iphone adc 网站的示例使您可以检查 iphone 是否可以访问互联网。

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.

无语#2024-08-11 19:33:17

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

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;
    }
}   
初雪2024-08-11 19:33:17

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文