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

标签 ios iphone-privateapi core-telephony signal-strength ios8.3

如何在 ios 8.3 中使用私有(private) api 获取小区 ID,因为以前的核心电话私有(private) api 在最新的 ios sdk 8.3 中不起作用。

最佳答案

您仍然可以使用它。它适用于 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);

编辑:我找到了如何获取信号强度的解决方案。 *!请注意,以下解决方案使用私有(private) API,因此在提交到 App Store 时会被 Apple 拒绝。

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 - 在 iOS 8.3 中获取 CellID、MCC、MNC、LAC、信号强度、质量和网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29795817/

相关文章:

ios - Firebase 观察者事件类型

ios - 无法将具有通用类型的类添加到 swift Realm

ios - 不使用桥接 header 访问私有(private) UIKit 函数

ios - 如何以编程方式检测 iOS 中调用处于保持状态?

iPhone后台应用程序在接到电话时更新屏幕

ios - 如何在 swift 3 中将滑动手势添加到 AVPlayer

ios - 滚动 UITableView 期间计时器将重置并停止运行

ios - 使用私有(private) API 强制 iOS 应用程序在前台打开

ios - 使用 App-prefs :root? 是否被视为私有(private) API

iphone - 有没有办法判断用户打电话时是否正在使用您的应用程序?