Get CellID, MCC, MNC, LAC, Signal strength, quality and Network in iOS 8.3

前端 未结 2 2025
生来不讨喜
生来不讨喜 2020-12-15 02:09

How to get cell id using private apis in ios 8.3 as previous core telephony private apis are not working in latest ios sdk 8.3.

2条回答
  •  无人及你
    2020-12-15 02:38

    You can still use this. It's working on iOS 8.3. I don't know how to get signal strength. Apple has changed many things in Core Telephony lately. :(

    CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new];
    NSString *carrierNetwork = telephonyInfo.currentRadioAccessTechnology;
    NSLog(@"Mobile Network): %@", carrierNetwork);
    
    CTCarrier *carrier = [telephonyInfo subscriberCellularProvider];
    
    NSString *mobileCountryCode = [carrier mobileCountryCode];
    NSLog(@"Mobile Country Code (MCC): %@", mobileCountryCode);
    
    NSString *mobileNetworkCode = [carrier mobileNetworkCode];
    NSLog(@"Mobile Network Code (MNC): %@", mobileNetworkCode);
    
    NSString *carrierName = [carrier carrierName];
    NSLog(@"Mobile Network name: %@", carrierName);
    
    NSString *isoCountryCode = [carrier isoCountryCode];
    NSLog(@"Mobile Network isoCode: %@", isoCountryCode);
    

    Edit: I found solution how to get signal strength. *! Please note that the solution below makes use of private API and as such will be rejected by Apple when submitted to the App Store.

    UIApplication *app = [UIApplication sharedApplication];
    NSArray *subviews = [[[app valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
    NSString *dataNetworkItemView = nil;
    
    for (id subview in subviews) {
        if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarSignalStrengthItemView") class]]) {
            dataNetworkItemView = subview;
            break;
        }
    }
    
    int signalStrength = [[dataNetworkItemView valueForKey:@"signalStrengthRaw"] intValue];
    
    NSLog(@"signal %d", signalStrength);
    

提交回复
热议问题