Check the network connection status of the device through the reachability library.
Class Library used: reachability
Reachability Library, is an iOS environment, the detection device network status of the library, you can search for downloads on the network.
Imported into the project before use.
Then add the following code within the View controller file (VIEWCONTROLLER.M)
Import the network State Library #import "Reachability.h"
1 //used to detect if the network has functions2-(BOOL) isexistencenetwork3 {4 BOOL isexistencenetwork;5 6 //test whether the network can connect to Apple's website. For friends who use IAP, you can use it to detect if you can connect to itunes. 7reachability *r = [reachability reachabilitywithhostname:@"http://www.apple.com"];8 //traversing a network connection9 Switch([R Currentreachabilitystatus]) {Ten CaseNotreachable://indicates a state in which the network is unavailable. OneIsexistencenetwork =FALSE; A Break; - CaseReachableviawwan://represents the network through the 2G/3G/4G link. -Isexistencenetwork =TRUE; the Break; - CaseReachableviawifi://represents the current network over a Wi-Fi link. -Isexistencenetwork =TRUE; - Break; + } - + returnisexistencenetwork; A}
Then add the test code inside the Viewdidload function:
1 BOOL canconnectnetwork = [self isexistencenetwork]; 2 3 NSLog (@ "Can Connect network--------%d", canconnectnetwork);
These are the features we want!
IOS network with multi-threaded--1. Detecting Network link status