Determining 3G vs Edge
I know that the reachability example allows detection of whether network is accessible via Wifi or Cell, but is there a way to determine whether the cell connection is over 3G or EDGE?
Solution 1:
As of iOS 7, there's now a public way to do so:
CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new];
NSLog(@"Current Radio Access Technology: %@", telephonyInfo.currentRadioAccessTechnology);
[NSNotificationCenter.defaultCenter addObserverForName:CTRadioAccessTechnologyDidChangeNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note)
{
NSLog(@"New Radio Access Technology: %@", telephonyInfo.currentRadioAccessTechnology);
}];
Read up more on my article in objc.io.
Solution 2:
Marginally simplified version of nst's code to silence compiler warnings I got in XCode 4.5:
- (NSNumber *) dataNetworkTypeFromStatusBar {
UIApplication *app = [UIApplication sharedApplication];
NSArray *subviews = [[[app valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
NSNumber *dataNetworkItemView = nil;
for (id subview in subviews) {
if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
dataNetworkItemView = subview;
break;
}
}
return [dataNetworkItemView valueForKey:@"dataNetworkType"];
}
And the value keys I've found so far:
- 0 = No wifi or cellular
- 1 = 2G and earlier? (not confirmed)
- 2 = 3G? (not yet confirmed)
- 3 = 4G
- 4 = LTE
- 5 = Wifi