• iOS 网络监测


    iOS网络监测,监测单个页面写在ViewController里,监测全部写在AppDelegate中,而且不用终止

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view, typically from a nib.

        

        //根据主机名判断网络是否连接

        self.reach = [Reachability reachabilityWithHostName:@"www.baidu.com"];

        

        //注册网络监听通知

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(kReachabilityChanged) name:kReachabilityChangedNotification object:nil];

        

        //开启监听

        [self.reach startNotifier];

        

    }

    -(void)kReachabilityChanged{

        switch (self.reach.currentReachabilityStatus) {

            case NotReachable:

                NSLog(@"没有网");

                break;

            case ReachableViaWiFi:

                NSLog(@"wifi");

                break;

            case ReachableViaWWAN:

                NSLog(@"移动蜂窝网");

                break;

            default:

                NSLog(@"未知网络");

            break;

        }

    }

    -(void)dealloc{

        //把当前的对象所有通知删除

        [[NSNotificationCenter defaultCenter] removeObserver:self];

        //停止监听

        [self.reach stopNotifier];

    }

  • 相关阅读:
    Zookeeper_ZAB协议
    Zookeeper_Paxos算法
    Eureka的表兄弟Zookeeper理论基础
    SSE:服务器推送事件
    BIO、NIO、AIO入门认识
    c语言float、double数据保留2位小数
    c语言在8位bmp位图上画一个框并另存
    C语言在24真彩位图上指定位置处画一条横线
    vs2010 opengl 环境搭建
    osg模型操作之替代节点
  • 原文地址:https://www.cnblogs.com/hlgbys/p/5286537.html
Copyright © 2020-2023  润新知