//1.创建网络状态监测管理者
AFNetworkReachabilityManager *mangerStatus = [AFNetworkReachabilityManager sharedManager];
//2.监听改变
[mangerStatus setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
/*
AFNetworkReachabilityStatusUnknown = -1,
AFNetworkReachabilityStatusNotReachable = 0,
AFNetworkReachabilityStatusReachableViaWWAN = 1,
AFNetworkReachabilityStatusReachableViaWiFi = 2,
*/
if (status == 1) {
//临时备用. 写的alertView ,真的用的时候要换成alertVC
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
message:@"您当前正在非WIFI环境,是否继续播放"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"继续",nil];
[alert show];
return;
}else{
[self createData];
}
}];
//开启监听,记得开启,不然不走block
[mangerStatus startMonitoring];
在当前页改变网络的的时候会自动监听进入. 但是两次以后.我自己试的就不走了...