引入:AFNetworkReachabilityManager.h文件
引入:AFNetworkReachabilityManager.m文件一:程序一启动,就监测
//
// AppDelegate.m
// afnetworking
//
// Created by lcy on 2015/7/5.
// Copyright © 2015年 ZG. All rights reserved.
//
#import "AppDelegate.h"
#import "AFNetworkReachabilityManager.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 判断网络状态
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
// 当网络状态改变时调用
switch (status) {
case AFNetworkReachabilityStatusUnknown:
NSLog(@"未知网络");
break;
case AFNetworkReachabilityStatusNotReachable:
NSLog(@"没有网络");
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"手机自带网络");
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"WIFI");
break;
}
}];
//开始监控
[manager startMonitoring];
return YES;
}
@end