Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C determine data network type of the iOS device

Tags:

Im on an application that receive data from server, the problem is when user connect to cellular data (Not 3G or WIFI), it take ages to receive data.

i had implemented this code from this Answer but im not sure if it is effective or not, sometimes it's giving me an accurate type, and sometimes it don't.

here is my code:

- (void)newtworkType {  NSArray *subviews = [[[[UIApplication sharedApplication] valueForKey:@"statusBar"] valueForKey:@"foregroundView"]subviews]; NSNumber *dataNetworkItemView = nil;  for (id subview in subviews) {     if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {         dataNetworkItemView = subview;         break;     } }  switch ([[dataNetworkItemView valueForKey:@"dataNetworkType"]integerValue]) {     case 0:         NSLog(@"No wifi or cellular");         break;      case 1:         NSLog(@"2G");         break;      case 2:         NSLog(@"3G");         break;      case 3:         NSLog(@"4G");         break;      case 4:         NSLog(@"LTE");         break;      case 5:         NSLog(@"Wifi");         break;       default:         break; }} 

is this the best i can do??, i tried Apple Reachability example, but it can determine if reachabilityForInternetConnection or just reachabilityForLocalWiFi but that not helpfull in my case.

Thanks in advance.

like image 591
Mutawe Avatar asked May 27 '13 14:05

Mutawe


1 Answers

if using iOS 7+ then you can get information from CoreTelephony framework following method :

CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new]; NSLog(@"Current Radio Access Technology: %@", telephonyInfo.currentRadioAccessTechnology); 

Possibles values defined which you will get are as follows : CTRadioAccessTechnologyGPRS, CTRadioAccessTechnologyEdge ,CTRadioAccessTechnologyWCDMA , CTRadioAccessTechnologyLTE etc

like image 137
muzz Avatar answered Sep 28 '22 06:09

muzz