嗨,我需要了解 iPhone 互联网是否连接 3G 或 2G 或 WIFI 网络有任何建议
谢谢
斯拉万
从此链接下载适用于 iOS 的可达性类:- https://github.com/tonymillion/Reachability
1)在您的 Project 中添加 Reachability.h &.m,确保通过添加标志 -fno-objc-arc 使其与 ARC 兼容
2)现在,检查视图控制器中的连接类型
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
}
您可以使用Reachability
tonymillion 编写的库。如果你不想使用 ARC,还有 Apple Reachability 库。
还要看看 <CoreTelephony/CTTelephonyNetworkInfo.h > 的内部
您将看到 CTTelephonyNetworkInfo 上公开了 currentRadioAccessTechnology 属性。
CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
NSLog(@"Radio access technology:\n%@",
netInfo.currentRadioAccessTechnology);
您可以通过以下方式订阅更改:
[NSNotificationCenter.defaultCenter
addObserverForName:CTRadioAccessTechnologyDidChangeNotification
object:nil
queue:nil
usingBlock:^(NSNotification __unused *notification) {
CTTelephonyNetworkInfo *current =
[[CTTelephonyNetworkInfo alloc] init];
NSLog(@"Updated Radio access technology:\n%@",
current.currentRadioAccessTechnology);
}];