How to detect at realtime the increase/decrease of cellular signal power in iOS
Asked Answered
S

1

10

My app (it is an app store app) is able to connect via 3G/4G/LTE/Edge etc... however it cannot detect at realtime (via a callback perhaps) that the strength of the signal have been modified. For example: If I am connected with 4G and I am in the "corner" where the signal is EDGE or 2G I would like to disable some functionality. Also I would like to re-enable the functionality with the signal becomes 4G again.

I have seen the CTTelephonyNetworkInfo class and also those values are offered in the SDK

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);

but how can the app receive a notification if one of those values are active. I have some code that reads from the CTTelephoneNetworkInfo and the values I am taking back are correct, however this is done when I am calling the methods manually.

Shipboard answered 7/4, 2016 at 15:44 Comment(2)
Please state in your question if the app you are working on is for the Apple store or enterprise app. The solution for each could be different.Demitria
You can check https://mcmap.net/q/443813/-measuring-cellular-signal-strength or https://mcmap.net/q/716031/-how-to-detect-network-signal-strength-in-ios-reachability , it may helpSuspense
E
6

To detect cellular signal power I use CTRadioAccessTechnologyDidChangeNotification.

You can try this code :

import CoreTelephony

private var info: CTTelephonyNetworkInfo!

func createObserver() {
    self.info = CTTelephonyNetworkInfo();
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "currentAccessTechnologyDidChange",
            name: CTRadioAccessTechnologyDidChangeNotification, object: self.observerObject)
}

func currentAccessTechnologyDidChange() {
    if let currentAccess = self.info.currentRadioAccessTechnology {
        switch currentAccess {
        case CTRadioAccessTechnologyGPRS:
            print("GPRS")
        case CTRadioAccessTechnologyEdge:
            print("EDGE")
        case CTRadioAccessTechnologyWCDMA:
            print("WCDMA")
        case CTRadioAccessTechnologyHSDPA:
            print("HSDPA")
        case CTRadioAccessTechnologyHSUPA:
            print("HSUPA")
        case CTRadioAccessTechnologyCDMA1x:
            print("CDMA1x")
        case CTRadioAccessTechnologyCDMAEVDORev0:
            print("CDMAEVDORev0")
        case CTRadioAccessTechnologyCDMAEVDORevA:
            print("CDMAEVDORevA")
        case CTRadioAccessTechnologyCDMAEVDORevB:
            print("CDMAEVDORevB")
        case CTRadioAccessTechnologyeHRPD:
            print("HRPD")
        case CTRadioAccessTechnologyLTE:
            print("LTE")
        default:
            print("DEF")
        }
    } else {
        print("Current Access technology is NIL")
    }
}

I've tested it on my iphone by turning on/off airplane mode and I've noticed that sometimes I have to wait a bit more time for notification. So maybe the better way in your case will be just called info.currentRadioAccessTechnology and get the result when you need it. Of course, remember to remove observer when you don't need it anymore.

Apple documentation about this :

currentRadioAccessTechnology Discussion: The current radio access technology the device is registered with. May be NULL if the device is not registered on any network.

Additionaly, I do some research and I found an interesting answer which might help you.

Simple Obj-C version :

#import <CoreTelephony/CTTelephonyNetworkInfo.h>


CTTelephonyNetworkInfo *ctInfo = [CTTelephonyNetworkInfo new];
[[NSNotificationCenter defaultCenter] addObserverForName:CTRadioAccessTechnologyDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
    NSLog(@"current access radio access did change to : %@", ctInfo.currentRadioAccessTechnology); 
}];
Eradis answered 13/4, 2016 at 17:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.