Checking cellular network type in iOS
Asked Answered
A

5

2

I am working on an iOS app, and want to determine which type of cellular connection the device has.

I'm most interested in the kind of cellular network my device is using: 2G or 3G, or other.

However, the Reachability.h only provides checking for wifi or 3G.

How can I check for 2G, 3G, etc?

Auberta answered 5/3, 2012 at 3:22 Comment(2)
ios sdk have so many limitation - There are no identity check of 2g / 3g / LTE. Feeling poor after starting of development in iosConformal
possible duplicate of Determining 3G vs EdgeNoblewoman
S
12

2G / 3G cannot be distinguished via Reachability.h or any other third party libraries, as iPhone only provides network type information ( WWAN , WiFi , no Network ) to API.

However, if you are able to know the IP range of 2G or 3G network, you can determine which network speed / frequency the iPhone is using.

Shaffert answered 5/3, 2012 at 3:28 Comment(0)
G
15

in iOS 7.0+ we have CoreTelephony framework which can provide us the required details about network type.

CTTelephonyNetworkInfo *telephonyInfo = [[CTTelephonyNetworkInfo alloc] init];
    NSString *currentRadio = telephonyInfo.currentRadioAccessTechnology;
    if ([currentRadio isEqualToString:CTRadioAccessTechnologyLTE]) {
        // LTE

    } else if([currentRadio isEqualToString:CTRadioAccessTechnologyEdge]) {
        // EDGE

    } else if([currentRadio isEqualToString:CTRadioAccessTechnologyWCDMA]){
        // 3G

    }
Gules answered 17/11, 2014 at 11:1 Comment(0)
S
12

2G / 3G cannot be distinguished via Reachability.h or any other third party libraries, as iPhone only provides network type information ( WWAN , WiFi , no Network ) to API.

However, if you are able to know the IP range of 2G or 3G network, you can determine which network speed / frequency the iPhone is using.

Shaffert answered 5/3, 2012 at 3:28 Comment(0)
H
1

You can tell EDGE from 3G with this technique: Determining 3G vs Edge

Hertel answered 9/7, 2012 at 18:2 Comment(0)
A
1

The best method I have found:

+ (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"]; }

    /* Where
    0 = No wifi or cellular
    1 = 2G and earlier
    2 = 3G
    3 = 4G
    4 = LTE
    5 = Wifi
    */

Since method is checking the value of status bar, please be sure that status bar is not hidden in your application. If it is not visible, method will always return 0.

Ammerman answered 4/11, 2015 at 20:2 Comment(0)
G
1

For Swift 4

let telephonyInfo = CTTelephonyNetworkInfo()
    let currentRadio = telephonyInfo.currentRadioAccessTechnology
    if (currentRadio == CTRadioAccessTechnologyLTE) {
        // LTE
        print("LTE")
    } else if (currentRadio == CTRadioAccessTechnologyEdge) {
        // EDGE
          print("EDGE")
    } else if (currentRadio == CTRadioAccessTechnologyWCDMA) {
        // 3G
         print("3G")
    }
    else if(currentRadio==CTRadioAccessTechnologyHSDPA){
        // HSDPA
        print("HSDPA")
    }

Note:import CoreTelephony

Grillo answered 31/10, 2018 at 14:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.