iOS 13以上系统获取信号强度
该方式获取到的值是信号格数,并不是具体的信号值。如果需求只是来分析信号质量,可以采取这样的方法。具体的值目前还在研究中。 苹果真的是越来越防着我们知道具体的信号强度了。 难道以为我们不知道值就不知道他信号差了吗?(狗头)
if(@available(iOS13.0, *)) {
NSArray *arr = [UIApplication sharedApplication].connectedScenes.allObjects;
UIWindowScene*scene = arr.firstObject;
UIStatusBarManager*statusBarManager = scene.statusBarManager;
id statusBar =nil;
if([statusBarManagerrespondsToSelector:@selector(createLocalStatusBar)]) {
UIView*localStatusBar = [statusBarManagerperformSelector:@selector(createLocalStatusBar)];
if([localStatusBarrespondsToSelector:@selector(statusBar)]) {
statusBar = [localStatusBarperformSelector:@selector(statusBar)];
}
}
if(statusBar) {
idcurrentData = [[statusBarvalueForKeyPath:@"_statusBar"]valueForKeyPath:@"currentData"];
idcellularEntry = [currentDatavalueForKeyPath:@"cellularEntry"]; if([cellularEntryisKindOfClass:NSClassFromString(@"_UIStatusBarDataIntegerEntry")]) {
signalStrength = [[cellularEntryvalueForKey:@"displayValue"]intValue];
}
}
}
iOS13以下系统获取信号强度
UIApplication *app = [UIApplication sharedApplication];
NSArray*subviews = [[[appvalueForKey:@"statusBar"]valueForKey:@"foregroundView"]subviews];
NSString*dataNetworkItemView =nil;
for(idsubviewinsubviews) {
if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarSignalStrengthItemView") class]])
{
dataNetworkItemView = subview;
break;
}
}
NSIntegersignalStrength = [[dataNetworkItemViewvalueForKey:@"signalStrengthRaw"]intValue];
NSString*signalStrengthStr = [NSStringstringWithFormat:@"%lddBm",(long)signalStrength];