我不确定这是否可行,但我有这种情况.
我的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;
}
Run Code Online (Sandbox Code Playgroud) 我目前正在使用以下内容检查我的应用程序是否可以使用Wi-Fi:
#import <SystemConfiguration/SystemConfiguration.h>
static inline BOOL addressReachable(const struct sockaddr_in *hostAddress);
BOOL localWiFiAvailable()
{
struct sockaddr_in localWifiAddress;
bzero(&localWifiAddress, sizeof(localWifiAddress));
localWifiAddress.sin_len = sizeof(localWifiAddress);
localWifiAddress.sin_family = AF_INET;
// IN_LINKLOCALNETNUM is defined in <netinet/in.h> as 169.254.0.0
localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM);
return addressReachable(&localWifiAddress);
}
static inline BOOL addressReachable(const struct sockaddr_in *hostAddress)
{
const SCNetworkReachabilityRef target =
SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault,
(const struct sockaddr *)hostAddress);
if (target != NULL)
{
SCNetworkReachabilityFlags flags = 0;
const BOOL reachable = SCNetworkReachabilityGetFlags(target, &flags);
CFRelease(target);
return reachable && (flags & kSCNetworkFlagsReachable);
} …Run Code Online (Sandbox Code Playgroud) 可能重复:
Iphone检测到3g或wifi
有没有办法获得当前的网络速度或设备是否在EDGE/3G/GPRS?我可以使用Reachability来区分WiFI和WMAN,但这对我的应用来说还不够.