How to detect carrier connection type (3G / EDGE / GPRS)

Apple reachability class respond either your device is connected to Wi-Fi or WWAN(Cell).

Now, the question is “How to check network 2G or 3G in IOS”. Here is the code to detect 2G, 3G, 4G.

First of all, add CoreTelephony framework to your project.

In your AppDelegate.h Class, Import below class

#import "Reachability.h"
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>

Add the below code in AppDelegate.h file,

@property (nonatomic)NetworkStatus remoteHostStatus;
@property (nonatomic)Reachability *reachability;

in AppDelegate.m file, add this

@synthesize remoteHostStatus;
@synthesize reachability;


reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
remoteHostStatus = [reachability currentReachabilityStatus];

if(remoteHostStatus == NotReachable) {
   NSLog(@"You have not internet");
}else if (remoteHostStatus == ReachableViaWiFi){
   NSLog(@"Connected via wifi");
}else if (remoteHostStatus == ReachableViaWWAN){
  NSLog(@"connected via cell");
  CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
  NSString *telCarrier = [[netinfo subscriberCellularProvider] carrierName];
  NSLog(@"Your mobile carrier = %@",telCarrier);
  if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS]) {
  NSLog(@"2G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyEdge]) {
  NSLog(@"2G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyWCDMA]) {
  NSLog(@"3G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSDPA]) {
  NSLog(@"3G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSUPA]) {
  NSLog(@"3G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMA1x]) {
  NSLog(@"2G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORev0]) {
  NSLog(@"3G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevA]) {
  NSLog(@"3G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevB]) {
  NSLog(@"3G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyeHRPD]) {
  NSLog(@"3G");
} else if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) {
  NSLog(@"4G");
}

That’s It. If you like this post, Please comment below or subscribe this blog.

Leave your comments

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s