标签:开始 tar pre 通知 重要 tno stat set cal
1.- (void)afnMonitoring
2.{
3. // 开始网络监控
4. AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
5.
6. [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
7. NSLog(@"-----当前的网络状态---%zd", status);
8. }];
9.
10. [mgr startMonitoring];
11.
12. // 拿到当前网络状态
13.// mgr.networkReachabilityStatus;
14.}
?备注
:enum {
//未知网络
AFNetworkReachabilityStatusUnknown,//
无网络连接
AFNetworkReachabilityStatusNotReachable,//
手机自带网络(3G | 4G)
AFNetworkReachabilityStatusReachableViaWWAN,//
无线网络
AFNetworkReachabilityStatusReachableViaWiFi,
}
1.- (void)appleMonitoring
2.{
3. // 监听通知
4. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getNetworkStatus) name:kReachabilityChangedNotification object:nil];
5.
6. // 开始监控网络
7. self.reachability = [Reachability reachabilityForInternetConnection];
8. [self.reachability startNotifier];
9.}
10.
11.- (void)dealloc
12.{
13. [[NSNotificationCenter defaultCenter] removeObserver:self];
14.
15. [self.reachability stopNotifier];
16. self.reachability = nil;
17.}
18.
19.- (void)getNetworkStatus
20.{
21. if ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus != NotReachable) {
22. NSLog(@"是wifi");
23. } else if ([Reachability reachabilityForInternetConnection].currentReachabilityStatus != NotReachable) {
24. NSLog(@"是手机自带网络");
25. } else {
26. NSLog(@"网络有问题");
27. }
28.}
29.
?重要
:
标签:开始 tar pre 通知 重要 tno stat set cal
原文地址:http://www.cnblogs.com/leilifengixng/p/6367495.html