选择提示框UIAlertController 和网络状态判断AFNetworking

// 选择提示框
            DownloadView *vc = [[DownloadView alloc] initWithFrame:CGRectMake(0, 0, 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 -1:
                        NSLog(@"未知网络");
                        break;
                    case 0:
                        NSLog(@"网络不可达");
                        break;
                    case 1:
                        
                        NSLog(@"GPRS网络");
                        break;
                    case 2:
                        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];
                }
            }];
原文地址:https://www.cnblogs.com/dujiahong/p/7453293.html