iOS network monitoring, monitoring individual pages written in Viewcontroller, monitoring all written in appdelegate, without termination
-(void) Viewdidload {
[Super Viewdidload];
Additional setup after loading the view, typically from a nib.
Determine if the network is connected based on host name
Self.reach = [reachability reachabilitywithhostname:@ "www.baidu.com"];
Register for network Monitoring notifications
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (kreachabilitychanged) Name: Kreachabilitychangednotification Object:nil];
Turn on monitoring
[Self.reach Startnotifier];
}
-(void) kreachabilitychanged{
Switch (self.reach.currentReachabilityStatus) {
Case Notreachable:
NSLog (@ "no net");
Break
Case Reachableviawifi:
NSLog (@ "WiFi");
Break
Case Reachableviawwan:
NSLog (@ "mobile cellular network");
Break
Default
NSLog (@ "Unknown network");
Break
}
}
-(void) dealloc{
Remove all notifications from the current object
[[Nsnotificationcenter Defaultcenter] removeobserver:self];
Stop listening
[Self.reach Stopnotifier];
}
IOS Network Monitoring