Prerequisite: Import ASIHTTPRequest--reachability
This method relies on the ability to open a set URL to determine whether the current network is disconnected or connected and what type of network is being determined
reachability *reachability =[reachability reachabilitywithhostname:@ "www.baidu.com"];
To obtain the current network status:
NetworkStatus status =[reachability Currentreachabilitystatus];
Switch (status) {
Case Knotreachable:
NSLog (@ "No network connection");
Break
Case Kreachableviawwan:
NSLog (@ "mobile network");
Break
Case Kreachableviawifi:
NSLog (@ "WiFi");
Break
Default
Break
}
Online Reprint--never tried.
Get iOS 2G 3G 4G network-like
Nsarray *subviews = [[[[UIApplication Sharedapplication] valueforkey:@ "StatusBar"] valueforkey:@ "Foregroundview"] Subviews];
NSNumber *datanetworkitemview = nil;
//
For (ID subview in subviews) {
if ([Subview iskindofclass:[nsclassfromstring (@ "Uistatusbardatanetworkitemview") class]) {
Datanetworkitemview = Subview;
Break
// }
// }
switch ([[Datanetworkitemview valueforkey:@ "Datanetworktype"]integervalue]) {
Case 0:
NSLog (@ "No WiFi or cellular");
Break
//
Case 1:
NSLog (@ "2G");
Break
//
Case 2:
NSLog (@ "3G");
Break
//
Case 3:
NSLog (@ "4G");
Break
//
Case 4:
NSLog (@ "LTE");
Break
//
Case 5:
NSLog (@ "Wifi");
Break
//
Default
Break
// }
Determine network connectivity