pragma mark --查看信号强度
// 3: 强 ,2:中, 1:弱 ,无
-(int)getSignalStrength{
UIApplication *app =[UIApplication sharedApplication];
// iphoneX状态栏和其他iPhone设备不同,变化比较大
//判断是否是iPhoneX
if([[app valueForKeyPath:@"_statusBar"] isKindOfClass:
NSClassFromString(@"UIStatusBar_Modern")]){
NSString *wifiEntry =[[[
[app valueForKey:@"statusBar"]
valueForKey:@"_statusBar"]
valueForKey:@"_currentAggregatedData"]
valueForKey:@"_wifiEntry"];
int signalStrength =[[wifiEntry valueForKey:@"_displayValue"]intValue];
return signalStrength;
}
else{
NSArray *subviews =[[[app valueForKey:@"statusBar"]
valueForKey:@"foreground
View"]subviews];
NSString *dataNetworkItemView = nil;
for(id subview in subviews){
if([subview isKindOfClass:
[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]){
dataNetworkItemView = subview;
break;
}
}
int signalStrength =[[dataNetworkItemView valueForKey:@"_wifiStrengthBars"] intValue];
return signalStrength;
}
}
利用lldb 命令:
打印视图层次: po [view recursiveDescription]
非iphoneX:
imageiphoneX:
image参考:
网友评论