1. If you only want to determine whether the current is a no-net state:
if ([reachability reachabilityforlocalwifi].currentreachabilitystatus==notreachable&&[[reachability Reachabilityforinternetconnection] currentreachabilitystatus]==notreachable)
{
The operation without net
}else
{
Network-aware operation
}
2. Monitor network status changes
Import Header File
#import "Reachability.h"
Registration Notice
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (networkstatechange:) Name: Kreachabilitychangednotification Object:nil];
Self.conn = [reachability reachabilityforinternetconnection];
[Self.conn Startnotifier];
(The conn of the above code is the Reachability object)
-(void) Networkstatechange: (nsnotification *) Note
{
Gets the reachability object being monitored by a notification object
reachability *curreach = [Note Object];
Gets the network state of the Reachability object
NetworkStatus status = [Curreach currentreachabilitystatus];
if (status = = Reachableviawwan)
{
NSLog (@ "3G online");
}else if (status = = Reachableviawifi)
{
NSLog (@ "WiFi online");
}else if (status = = Notreachable)
{
NSLog (@ "no net");
}
}
IOS determines current network status