我在我的项目中使用可达性库,它允许我检查是否有任何连接,但我现在要做的是通知用户连接是 2G 还是非常慢。当用户在 GSM 通话中并在互联网设置为 2G 时尝试与应用程序交互时,这会导致问题。我想通知他们,也许说他们应该更改移动数据设置或连接到 Wifi。我一直在尝试在连接检查块内使用 CTTelephonyNetworkInfo 代码,但它不会在互联网低速时通知应用程序,有时我可以复制来自此呼叫的消息。有任何想法吗?
switch (_tcpipReachability.currentReachabilityStatus) {
case ReachableViaWiFi:
self.networkAccessible = (self.wifiReachability.currentReachabilityStatus != NotReachable);
break;
case ReachableViaWWAN:
self.networkAccessible = self.useOperatorBearer;
break;
case NotReachable:
default:
self.networkAccessible = NO;
break;
}
//connection type
CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS]) {
NSLog(@"2G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyEdge]) {
NSLog(@"2G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyWCDMA]) {
NSLog(@"3G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSDPA]) {
NSLog(@"3G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSUPA]) {
NSLog(@"3G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMA1x]) {
NSLog(@"2G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORev0]) {
NSLog(@"3G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevA]) {
NSLog(@"3G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevB]) {
NSLog(@"3G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyeHRPD]) {
NSLog(@"3G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) {
NSLog(@"4G");
}