zoukankan      html  css  js  c++  java
  • 2016-02-22 有无网络 2

      //gzz0220 网络检测通知

        // 网络监测

        

        // 监测网络情况

        [[NSNotificationCenter defaultCenter] addObserver:self

                                                 selector:@selector(reachabilityChanged:)

                                                     name: kReachabilityChangedNotification

                                                   object: nil];

        hostReach = [Reachability reachabilityWithHostName:@"www.google.com"];

        [hostReach startNotifier];

    #pragma mark 网络监测

    - (void)reachabilityChanged:(NSNotification *)note {

        Reachability* curReach = (Reachability*)[note object];

        

        

        //    NSParameterAssert([curReach isKindOfClass: [Reachability class]]);

        //    NetworkStatus status = [curReach currentReachabilityStatus];

        // NSLog(@"stature  ==%d  notreachable ==%d",status,NotReachable);

        // NSString * str =[NSString stringWithFormat:@"%d",status];

        //    BOOL connectionRequired = [curReach connectionRequired];

        NetworkStatus   statNetWork =  [curReach currentReachabilityStatus];

        

        

        if ( statNetWork  == NotReachable) {

            

            UIView *view = [[UIApplication sharedApplication].delegate window];

            MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];

            hud.userInteractionEnabled = NO;

            hud.mode = MBProgressHUDModeText;

            hud.labelText = @"暂无网络";

            hud.margin = 10.f;

            hud.yOffset =ConentViewHeight / 2 - 100;

            hud.removeFromSuperViewOnHide = YES;

            [hud hide:YES afterDelay:2];

            

        }else{

            //

            //        UIView *view = [[UIApplication sharedApplication].delegate window];

            //        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];

            //        hud.userInteractionEnabled = NO;

            //        hud.mode = MBProgressHUDModeText;

            //        hud.labelText = @"网络恢复";

            //        hud.margin = 10.f;

            //        hud.yOffset = ConentViewHeight / 2 - 100;

            //        hud.removeFromSuperViewOnHide = YES;

            //        [hud hide:YES afterDelay:2];

            //

            

            

            

            

        }

    }

  • 相关阅读:
    【转】 Shiro 核心功能案例讲解 基于SpringBoot 有源码
    【转】 SpringData 基于SpringBoot快速入门
    【转】 Dubbo整合SpringBoot
    【转】 SpringBoot war包部署到Tomcat服务器
    【转】 SpringBoot使用Redis缓存
    【转】 SpringBoot统一异常处理
    【转】 SpringBoot创建定时任务
    【转】 SpringBoot 多环境配置
    js小数运算出现误差
    vue中组件的data为什么是一个函数
  • 原文地址:https://www.cnblogs.com/gzz2016/p/5206825.html
Copyright © 2011-2022 走看看