iOS检测3G或WiFi我不确定这是否可行,但我有这种情况。我的UIWebView中显示了一个网站,该网站在UISegmentedController中设置了链接。他们的网站可以检测您是在wifi上还是在3g网络上。现在,分段控制器指向2个不同的页面:1 - iPhone友好登录屏幕2 - 主页,一旦您登录。现在问题是:我可以编程我的应用程序来检测它是WIFI还是3G(我知道你可以这样做),但是根据答案转到第1或第2部分有点像这样:if (iPhone device is on 3g) {
Go to Segment 1;} else {
Go to Segment 0;}
3 回答
皈依舞
TA贡献1851条经验 获得超3个赞
使用Apple在此处提供的代码
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
}
缥缈止盈
TA贡献2041条经验 获得超4个赞
如果您不想导入Reachability库或处理通知程序,则可以使用以下简单的同步方法:
typedef enum { ConnectionTypeUnknown, ConnectionTypeNone, ConnectionType3G, ConnectionTypeWiFi} ConnectionType;+ (ConnectionType)connectionType{ SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, "8.8.8.8"); SCNetworkReachabilityFlags flags; BOOL success = SCNetworkReachabilityGetFlags(reachability, &flags); CFRelease(reachability); if (!success) { return ConnectionTypeUnknown; } BOOL isReachable = ((flags & kSCNetworkReachabilityFlagsReachable) != 0); BOOL needsConnection = ((flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0); BOOL isNetworkReachable = (isReachable && !needsConnection); if (!isNetworkReachable) { return ConnectionTypeNone; } else if ((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0) { return ConnectionType3G; } else { return ConnectionTypeWiFi; }}
- 3 回答
- 0 关注
- 542 浏览
添加回答
举报
0/150
提交
取消