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

2018-03-07  本文已影响0人  762683ff5d3d

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

上一篇 下一篇

猜你喜欢

热点阅读