iOS检测3G或WiFi [英] iOS Detect 3G or WiFi
问题描述
我不确定这是否可行,但我有这种情况。
I am not sure if this is possible, but I have this scenario.
我的UIWebView中显示了一个网站,该网站在UISegmentedController中设置了链接。
他们的网站可以检测你是否使用wifi或3g网络。
I have a website displayed in my UIWebView which has the link set in a UISegmentedController. They website can detect if you are on wifi or on the 3g network.
现在分段控制器指向2个不同的页面:
1 - 一个iPhone友好的登录屏幕
2 - 主页,一旦你登录。
Now the segmented controller points to 2 different pages: 1 - An iPhone friendly login screen 2 - The home page, once you are logged in.
现在这里是一个问题:
我是否可以对我的应用程序进行编程以检测它是WIFI还是3G(我知道你可以这样做),但根据答案转到第1或第2段
Can I program my application to detect whether it is to WIFI or 3G (I know you can do this), but then based on the answer go to segment 1 or 2
有点像这样:
if (iPhone device is on 3g) {
Go to Segment 1;
} else {
Go to Segment 0;
}
推荐答案
使用Apple拥有的代码提供此处
Using the code that Apple has provided here
Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
NetworkStatus status = [reachability currentReachabilityStatus];
if(status == NotReachable)
{
//No internet
}
else if (status == ReachableViaWiFi)
{
//WiFi
}
else if (status == ReachableViaWWAN)
{
//3G
}
这篇关于iOS检测3G或WiFi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!