如何在iOS 8.3中使用私有API获取基站ID,因为先前的核心电话私有API在最新的iOS SDK 8.3中不起作用。
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);
编辑:我找到了获取信号强度的解决方案。 *!请注意,下面的解决方案使用了私有API,因此如果提交到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);
在iOS 5.1中获取CellID、MCC、MNC、LAC和网络
您可以访问上述链接,在iOS 8.2以下版本中获取LAC和Cell。 如果您想在iOS 8.3以上版本中获取LAC和Cell,您需要添加权限:
<key>com.apple.CommCenter.fine-grained</key>
<array>
<string>spi</string>
</array>