在iOS 8.3中获取CellID,MCC,MNC,LAC,信号强度,质量和网络

Poo*_*aha 4 iphone-privateapi signal-strength ios core-telephony ios8.3

如何在ios 8.3中使用私有api获取cell id,因为之前的核心电话私有api在最新的ios sdk 8.3中不起作用.

Mat*_*ski 5

你仍然可以使用它.它适用于iOS 8.3.我不知道如何获得信号强度.Apple最近在Core Telephony中改变了很多东西.:(

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);
Run Code Online (Sandbox Code Playgroud)

编辑:我找到了解决方案如何获得信号强度.*!请注意,下面的解决方案使用私有API,因此Apple在提交到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);
Run Code Online (Sandbox Code Playgroud)