Skip to content

Instantly share code, notes, and snippets.

@naotokui
Created October 31, 2012 05:36
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naotokui/3985027 to your computer and use it in GitHub Desktop.
Save naotokui/3985027 to your computer and use it in GitHub Desktop.
Detect Network Type on iOS ... from the status bar
// http://stackoverflow.com/questions/8400340/determining-3g-vs-edge
- (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"];
}
// 0 = No wifi or cellular
// 1 = 2G and earlier? (not confirmed)
// 2 = 3G? (not yet confirmed)
// 3 = 4G
// 4 = LTE
// 5 = Wifi
@pandaApe
Copy link

Does Apple allow to use this PRIVATE API ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment