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];
                    }
                }];
  • 相关阅读:
    Socket通信中的多进程编程(TCP/IP通信过程)
    AsyncSocket.h解读
    AsyncSocket编程
    命令行下文件名空格的处理
    socket编程 Asyncsocket (转)
    iPhone网络编程初体验简单的聊天程序 (转)
    2.0版本cocos2diphone 开发之CCProgressTimer制作游戏中的血条
    js 旋转图片
    css图片旋转
    数据结构之单向链表
  • 原文地址:https://www.cnblogs.com/dujiahong/p/7453293.html
Copyright © 2011-2022 走看看