zoukankan      html  css  js  c++  java
  • 选择提示框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];
                    }
                }];
  • 相关阅读:
    解决html中刷新页面后checkbox还选中的问题
    初始化spring容器的几种方法
    在web.xml中配置spring配置文件的路径
    查找算法
    排序算法
    ORACLE TO_CHAR,TO_DATE函数格式说明
    ORACLE TO_DATE函数
    ORACLE SUBSTR函数
    ORACLE学习笔记
    Linux 查看端口占用情况
  • 原文地址:https://www.cnblogs.com/dujiahong/p/7453293.html
Copyright © 2011-2022 走看看