mixpanel / mixpanel-iphone

Official iOS (Objective-C) Tracking Library for Mixpanel Analytics
http://mixpanel.com
Apache License 2.0
1.05k stars 564 forks source link

Fix deprecated `currentRadioAccessTechnology` in CTTelephonyNetworkInfo #899

Closed zihejia closed 4 years ago

zihejia commented 4 years ago

This will likely fix crash from currentRadioAccessTechnology and support Dual SIM

RK-medienpalast commented 4 years ago

I also have same issue. I am new to Objective C. Can you help me in solving problem of deprecated currentRadioAccessTechnology in CTTelephonyNetworkInfo. Xcode gives me error Replace 'currentRadioAccessTechnology' with 'serviceCurrentRadioAccessTechnology'

`- (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:@"12.0" options:NSNumericSearch] != NSOrderedAscending) {
                CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new];
                if ([telephonyInfo.currentRadioAccessTechnology  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";
}

} `