Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically detect cellular network type in iOS

Tags:

ios

I am facing some network related issue, need to check the cellular network type, like 2G,3G or 4G data network is selected.

like image 293
Vishnu Dayal Avatar asked Jul 15 '16 06:07

Vishnu Dayal


1 Answers

CoreTelephony.framework could provide you such details:

Objective-C

CTTelephonyNetworkInfo *telephonyInfo = [[CTTelephonyNetworkInfo alloc] init];
NSString *technologyString = telephonyInfo.currentRadioAccessTechnology;

if ([technologyString isEqualToString:CTRadioAccessTechnologyLTE]) {
    // LTE (4G)
} else if([technologyString isEqualToString:CTRadioAccessTechnologyWCDMA]){
    // 3G
} else if([technologyString isEqualToString:CTRadioAccessTechnologyEdge]) {
    // EDGE (2G)
}

Swift

import CoreTelephony

let telefonyInfo = CTTelephonyNetworkInfo()
if let radioAccessTechnology = telefonyInfo.currentRadioAccessTechnology{
  switch radioAccessTechnology{
  case CTRadioAccessTechnologyLTE: print("LTE (4G)")
  case CTRadioAccessTechnologyWCDMA: print("3G")
  case CTRadioAccessTechnologyEdge: print("EDGE (2G)")
  default: print("Other")
  }
}
like image 159
Juri Noga Avatar answered Nov 15 '22 12:11

Juri Noga