// 选择提示框
DownloadView *vc = [[DownloadView alloc] initWithFrame:CGRectMake(, , SCREEN_WIDTH, SCREEN_HEIGHT)];
[vc show]; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示"
message:@"当前GPRS网络,确定要下载吗?"
preferredStyle:UIAlertControllerStyleAlert ];
//添加取消到UIAlertController中
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"选择了取消");
}];
[alertController addAction:cancelAction]; //添加确定到UIAlertController中
UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"选择了确定");
}];
[alertController addAction:OKAction]; [self presentViewController:alertController animated:YES completion:nil]; // 网络状态
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
[[AFNetworkReachabilityManager sharedManager ] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case -:
NSLog(@"未知网络");
break;
case :
NSLog(@"网络不可达");
break;
case : NSLog(@"GPRS网络");
break;
case :
NSLog(@"wifi网络");
break;
default:
break;
}
if(status ==AFNetworkReachabilityStatusReachableViaWWAN || status == AFNetworkReachabilityStatusReachableViaWiFi)
{
NSLog(@"有网");
}else
{
NSLog(@"没有网");
UIAlertController *notNetWorking = [UIAlertController alertControllerWithTitle:@"提示"
message:@"网络失去连接"
preferredStyle:UIAlertControllerStyleAlert ];
//添加取消到UIAlertController中
UIAlertAction *cancelClick = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"选择了取消");
}];
[notNetWorking addAction:cancelClick];
[self presentViewController:notNetWorking animated:YES completion:nil];
}
}];