//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];
在當前頁改變網絡的的時候會自動監聽進入. 可是兩次之後.我本身試的就不走了...網絡