Created
October 31, 2012 05:36
-
-
Save naotokui/3985027 to your computer and use it in GitHub Desktop.
Detect Network Type on iOS ... from the status bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does Apple allow to use this PRIVATE API ?