Determining 3G vs Edge
Asked Answered
D

5

8

I know that the reachability example allows detection of whether network is accessible via Wifi or Cell, but is there a way to determine whether the cell connection is over 3G or EDGE?

Doublepark answered 6/12, 2011 at 13:3 Comment(0)
C
0

No, there is no such thing as a public detection of network technology within the cell connectivity.

Cadet answered 6/12, 2011 at 13:11 Comment(1)
IS there any reference to implement our private API for that which calculate the network characteristics like latency and bandwidth of the connected network.Doublepark
B
28

As of iOS 7, there's now a public way to do so:

CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new];
NSLog(@"Current Radio Access Technology: %@", telephonyInfo.currentRadioAccessTechnology);
[NSNotificationCenter.defaultCenter addObserverForName:CTRadioAccessTechnologyDidChangeNotification 
                                                object:nil 
                                                 queue:nil 
                                            usingBlock:^(NSNotification *note) 
{
    NSLog(@"New Radio Access Technology: %@", telephonyInfo.currentRadioAccessTechnology);
}];

Read up more on my article in objc.io.

Bloodyminded answered 15/10, 2013 at 9:50 Comment(3)
Is there a simple way how to incorporate WiFi option to this solution?Arillode
The Problem is that sometimes RAT has changed and the notifications gives null...Dilapidated
There is any manner to test that ? on the simulator. I tried Network Link Conditioner, but it simulate only the speed and the notification is never fired. Any help is welcomeNaaman
U
14

Marginally simplified version of nst's code to silence compiler warnings I got in XCode 4.5:

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

And the value keys I've found so far:

  • 0 = No wifi or cellular
  • 1 = 2G and earlier? (not confirmed)
  • 2 = 3G? (not yet confirmed)
  • 3 = 4G
  • 4 = LTE
  • 5 = Wifi
Unkennel answered 29/10, 2012 at 17:50 Comment(3)
how can i get the status when app is in backgroundCarrnan
Is it private api? If yes, apple will be rejected? any idea?Irs
The solution relies on private APIs and it is also a fragile logic that can break at any point.Suppositious
H
10

Using private APIs, you can read this information directly in the status bar.

https://github.com/nst/MobileSignal/blob/master/Classes/UIApplication+MS.m

+ (NSNumber *)dataNetworkTypeFromStatusBar {

    UIApplication *app = [UIApplication sharedApplication];

    UIStatusBar *statusBar = [app valueForKey:@"statusBar"];

    UIStatusBarForegroundView *foregroundView = [statusBar valueForKey:@"foregroundView"];

    NSArray *subviews = [foregroundView subviews];

    UIStatusBarDataNetworkItemView *dataNetworkItemView = nil;

    for (id subview in subviews) {
        if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
            dataNetworkItemView = subview;
            break;
        }
    }

    return [dataNetworkItemView valueForKey:@"dataNetworkType"];
}
Hohenzollern answered 9/7, 2012 at 17:54 Comment(5)
You'll probably want to wrap that in a @try-@catch block, that looks like it could change in a future iOS version. +1 though, very nice!Boundary
is this accepted by apple ? for publishing to the app store...?Prothallus
The solution relies on private APIs and it is also a fragile logic that can break at any point.Suppositious
As NST already stated this method does indeed use Private APIs which would not be accepted by Apple. This workaround was written in 2012, before the public API option presented by steipete was available. This is really here now for historical purposes and shouldn't be used.Unkennel
@JasonK. what is the appropriate alternative to this method using Swift?Vitrine
R
8

telephonyInfo.currentRadioAccessTechnology Values:

CORETELEPHONY_EXTERN NSString * const CTRadioAccessTechnologyGPRS          __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_7_0);
CORETELEPHONY_EXTERN NSString * const CTRadioAccessTechnologyEdge          __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_7_0);
CORETELEPHONY_EXTERN NSString * const CTRadioAccessTechnologyWCDMA         __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_7_0);
CORETELEPHONY_EXTERN NSString * const CTRadioAccessTechnologyHSDPA         __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_7_0);
CORETELEPHONY_EXTERN NSString * const CTRadioAccessTechnologyHSUPA         __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_7_0);
CORETELEPHONY_EXTERN NSString * const CTRadioAccessTechnologyCDMA1x        __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_7_0);
CORETELEPHONY_EXTERN NSString * const CTRadioAccessTechnologyCDMAEVDORev0  __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_7_0);
CORETELEPHONY_EXTERN NSString * const CTRadioAccessTechnologyCDMAEVDORevA  __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_7_0);
CORETELEPHONY_EXTERN NSString * const CTRadioAccessTechnologyCDMAEVDORevB  __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_7_0);
CORETELEPHONY_EXTERN NSString * const CTRadioAccessTechnologyeHRPD         __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_7_0);
CORETELEPHONY_EXTERN NSString * const CTRadioAccessTechnologyLTE __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_7_0);

I think that these are all the possible values.

Rookie answered 28/3, 2014 at 12:17 Comment(0)
C
0

No, there is no such thing as a public detection of network technology within the cell connectivity.

Cadet answered 6/12, 2011 at 13:11 Comment(1)
IS there any reference to implement our private API for that which calculate the network characteristics like latency and bandwidth of the connected network.Doublepark

© 2022 - 2024 — McMap. All rights reserved.