+(NSString *) getnetworkstates{
UIApplication*app = [UIApplication Sharedapplication];
Nsarray*children = [[[App Valueforkeypath]:@ "StatusBar"]valueforkeypath:@ "Foregroundview"]subviews];
NSString *state = [[NSStringAllocINIT];
int netType =0;
//Get to the network return code
for (ID ChildIn children) {
If([ChildIskindofclass:Nsclassfromstring(@ "Uistatusbardatanetworkitemview")]) {
//get to status bar
NetType = [[ChildValueforkeypath:@ "Datanetworktype"]Intvalue];
Switch (netType) {
Case0:
State =@"No network";
//No Network mode
Break
Case1:
State =@ "2G";
Break
Case2:
State =@ "3G";
Break
Case3:
State =@ "4G";
Break
Case {
&NB Sp state = @ "WIFI";
}
&NBSP ; break;
default:
&N Bsp break;
{
}
}
//
}
To obtain network status according to the status bar, can distinguish 2G, 3G, 4G, WIFI, System method, relatively fast. The only thing that hurts a little bit is if the Wi-Fi is not connected ... You know
Get network status, differentiate 2g3g4gwifi, etc., non-reachability