标签:
利用AFN进行网络状态监控:
#import "HMViewController.h" #import "AFNetworking.h" @interface HMViewController () @end @implementation HMViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager]; [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { // 当网络状态发生改变的时候调用这个block switch (status) { case AFNetworkReachabilityStatusReachableViaWiFi: NSLog(@"WIFI"); break; case AFNetworkReachabilityStatusReachableViaWWAN: NSLog(@"自带网络"); break; case AFNetworkReachabilityStatusNotReachable: NSLog(@"没有网络"); break; case AFNetworkReachabilityStatusUnknown: NSLog(@"未知网络"); break; default: break; } }]; // 开始监控 [mgr startMonitoring]; } - (void)dealloc { [[AFNetworkReachabilityManager sharedManager] stopMonitoring]; } @end
标签:
原文地址:http://www.cnblogs.com/ZMiOS/p/5071239.html