1
votes

I am new to Objective-C. I have problem with following code. it shows 'currentRadioAccessTechnology' is deprecated: first deprecated in iOS 12.0 and Replace 'currentRadioAccessTechnology' with 'serviceCurrentRadioAccessTechnology' If i replace my code. It gives following error No visible @interface for 'NSDictionary<NSString *,NSString *>' declares the selector 'isEqualToString:'

- (NSString*)w3cConnectionTypeFor:(CDVReachability*)reachability
{
    NetworkStatus networkStatus = [reachability currentReachabilityStatus];

    switch (networkStatus) {
        case NotReachable:
            return @"none";

        case ReachableViaWWAN:
        {
            BOOL isConnectionRequired = [reachability connectionRequired];
            if (isConnectionRequired) {
                return @"none";
            } else {
                if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) {
                    CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new];
                    if ([telephonyInfo.serviceCurrentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyGPRS]) {
                        return @"2g";
                    } else if ([telephonyInfo.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyEdge]) {
                        return @"2g";
                    } else if ([telephonyInfo.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyWCDMA]) {
                        return @"3g";
                    } else if ([telephonyInfo.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyHSDPA]) {
                        return @"3g";
                    } else if ([telephonyInfo.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyHSUPA]) {
                        return @"3g";
                    } else if ([telephonyInfo.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyCDMA1x]) {
                        return @"3g";
                    } else if ([telephonyInfo.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyCDMAEVDORev0]) {
                        return @"3g";
                    } else if ([telephonyInfo.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyCDMAEVDORevA]) {
                        return @"3g";
                    } else if ([telephonyInfo.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyCDMAEVDORevB]) {
                        return @"3g";
                    } else if ([telephonyInfo.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyeHRPD]) {
                        return @"3g";
                    } else if ([telephonyInfo.currentRadioAccessTechnology  isEqualToString:CTRadioAccessTechnologyLTE]) {
                        return @"4g";
                    }
                }
                return @"cellular";
            }
        }
        case ReachableViaWiFi:
        {
            BOOL isConnectionRequired = [reachability connectionRequired];
            if (isConnectionRequired) {
                return @"none";
            } else {
                return @"wifi";
            }
        }
        default:
            return @"unknown";
    }
}
1
serviceCurrentRadioAccessTechnology is a dictionary, not a string since devices may have dual SIMs and therefore more than one carrier. You need to get the value from each dictionary entry. Retrieve the dictionary keys and use that to access the service types. - Paulw11
Your app really shouldn't make decisions based on the kind of connectivity anyway. The network framework can tell you whether you are on a low data network and you can make decisions based on that. - Paulw11

1 Answers

0
votes

You need to use something like:

let dict = CTTelephonyNetworkInfo().serviceCurrentRadioAccessTechnology
let firstValue = dict.values.first 

as equivalent to old

serviceCurrentRadioAccessTechnology