美文网首页
WiFi 信号强度获取(适配iPhoneX)

WiFi 信号强度获取(适配iPhoneX)

作者: 762683ff5d3d | 来源:发表于2018-03-07 10:41 被阅读0次

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:

image

iphoneX:

image

参考:

http://lldb.llvm.org/varformats.html

相关文章

网友评论

      本文标题:WiFi 信号强度获取(适配iPhoneX)

      本文链接:https://www.haomeiwen.com/subject/svxjfftx.html