• 选择提示框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];
                    }
                }];
  • 相关阅读:
    Java中容器的两种初始化方式比较
    java8之stream
    java8之lambda表达式入门
    java8之lambda表达式(1)-基本语法
    java中Comparable和Comparator两种比较器的区别
    将博客搬至CSDN
    vsphere6.5 创建数据中心、集群和添加主机
    VMware-VCSA-6.5安装过程
    docker--数据卷与数据卷容器
    docker私有库搭建过程(Registry)
  • 原文地址:https://www.cnblogs.com/dujiahong/p/7453293.html
Copyright © 2020-2023  润新知