//
// ViewController.m
// AFN实现网络监测
//
// Created by 唐帅 on 14/7/3.
// Copyright © 2014年 Iteima. All rights reserved.
//
#import "ViewController.h"
#import "AFNetworking.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self netWork];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)netWork
{
// 1.创建网络监测单例
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
/*
status
AFNetworkReachabilityStatusUnknown = -1, 不知道监测的是什么
AFNetworkReachabilityStatusNotReachable = 0, 没有检测到网络
AFNetworkReachabilityStatusReachableViaWWAN = 1, 蜂窝网
AFNetworkReachabilityStatusReachableViaWiFi = 2, WIFI
*/
// 2.实现网络监测的回调
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
NSLog(@"%zd",status);
}];
// 3.开始监测
[manager startMonitoring];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end