zoukankan      html  css  js  c++  java
  • 关于苹果官方网站Reachability检测网络的总结

    Reachability类库版本在实时更新,官方参考demo及库下载地址,目前已到2.2的版本了:http://developer.apple.com/library/ios/#samplecode/Reachability/Listings/Classes_ReachabilityAppDelegate_m.html#//apple_ref/doc/uid/DTS40007324-Classes_ReachabilityAppDelegate_m-DontLinkElementID_4

    之前项目中使用的方式如下:(实时监控网络的方法,2.0版本的) 注意:当程序在启动的时就没网络,实时监控会没有作用,也就是说,这样即使网络从无到有或是从有到无 都不会监控的到
      - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
        self.hostReachable = [CheckNetReachability reachabilityWithHostName:@"www.google.com"];
        [self.hostReachable startNotifier];
       
        return YES;
    }

    #pragma mark - check the network

    - (void)reachabilityChanged:(NSNotification *)notification {
        Reachability *curReach = [notification object];
        NetworkStatus status = [curReach currentReachabilityStatus];
        if (status == NotReachable) {
            [AlertBox showConfirm:nil message:@"已失去网络连接!" firstButtonTitle:@"好的" secondButtonTitle:nil delegate:self tag:0];
           。。。。。。。。。
        }else{
            if (!_isFirstLoad) {
                [AlertBox showConfirm:nil message:@"已连接上网络!" firstButtonTitle:@"好的" secondButtonTitle:nil delegate:self tag:0];
                。。。。。。。。。。。。。。
        }
    }
  • 相关阅读:
    新式类、经典类与多继承
    实现抽象类之方式二
    实现抽象类之方式一
    re模块
    28个高频Linux命令
    Git使用教程
    编程语言介绍
    编码
    进制
    操作系统简史
  • 原文地址:https://www.cnblogs.com/cnsec/p/11515859.html
Copyright © 2011-2022 走看看