AFNetworkReachabilityManager * mgr = [AFNetworkReachabilityManager sharedManager];
[mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
// 当网络状态发生改变的时候调用这个block
switch (status) {
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"WIFI");
[[NSUserDefaults standardUserDefaults] setObject:@"wifi" forKey:@"network"];
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"自带网络");
[[NSUserDefaults standardUserDefaults] setObject:@"3g" forKey:@"network"];
break;
case AFNetworkReachabilityStatusNotReachable:
NSLog(@"没有网络");
[[NSUserDefaults standardUserDefaults] setObject:@"without" forKey:@"network"];
break;
case AFNetworkReachabilityStatusUnknown:
NSLog(@"未知网络!");
[[NSUserDefaults standardUserDefaults] setObject:@"unknown" forKey:@"network"];
break;
default:
break;
} }];
// 开始监控
[mgr startMonitoring];
新闻热点
疑难解答