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屋!