[英]iphone how to check the Airplane mode?
嗨,
我想檢查是否打開飛機模式..如何檢查?
謝謝+如何檢查用戶是否正在使用WIFI或GPRS或EDGE。 如何區分?
如果您只想要顯示通知,當用戶處於飛行模式時,則足以在您應用的plist文件中啟用SBUsesNetwork屬性。 當您的代碼使用網絡時,系統會提示用戶自動關閉飛行模式。
參見例如這篇文章 。
我不確定您是否可以專門檢查飛機模式,但是來自iphone adc網站的可達性示例可以讓您檢查iphone是否可以訪問互聯網。
這回答了問題的第二部分 - 如何判斷用戶所處的網絡類型(Wifi或3g /邊緣)。 它使用Apple的Reachability代碼。 將它放在app delegate中的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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.