iOS developed to get WiFi signal strength

Source: Internet
Author: User

Although the various APIs that directly get signal strength are blocked. But there is another kind of black magic that can be acquired. That's traversing the uistatusbar.

- (void) getsignalstrength{uiapplication*app =[UIApplication sharedapplication]; Nsarray*subviews = [[[App Valueforkey:@"StatusBar"] Valueforkey:@"Foregroundview"] subviews]; NSString*datanetworkitemview =Nil;  for(IDSubviewinchsubviews) {        if([Subview iskindofclass:[nsclassfromstring (@"Uistatusbardatanetworkitemview")class]]) {Datanetworkitemview=Subview;  Break; }    }        intSignalstrength = [[Datanetworkitemview valueforkey:@"_wifistrengthbars"] intvalue]; NSLog (@"Signal%d", signalstrength);}

Of course we can also traverse Uistatusbar to get to the network connection type

- (void) getnetworktype{uiapplication*app =[UIApplication sharedapplication]; Nsarray*subviews = [[[App Valueforkeypath:@"StatusBar"] Valueforkeypath:@"Foregroundview"] subviews];  for(IDSubviewinchsubviews) {        if([Subview iskindofclass:nsclassfromstring (@"Uistatusbardatanetworkitemview")]) {            intNetworktype = [[Subview valueforkeypath:@"Datanetworktype"] intvalue]; Switch(networktype) { Case 0: NSLog (@"NONE");  Break;  Case 1: NSLog (@"2G");  Break;  Case 2: NSLog (@"3G");  Break;  Case 3: NSLog (@"4G");  Break;  Case 5: {NSLog (@"WIFI"); }                     Break; default:                     Break; }        }    }}

iOS developed to get WiFi signal strength

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.