zoukankan      html  css  js  c++  java
  • Reachability

    一、Reachability中介绍了取得/检测网络状态的方法。

    二、使用

        1、添加源文件:Reachability.h和Reachability.m

        2、添加framework———SystemConfiguration.framework

    三、网络状态

        Reachability.h定义了三中网络状态

     typedef enum{
    
            NotReachable = 0,   //无连接
    
            ReachableViaWiFi,   //使用3G/GPRS网络
    
            ReachableViaWWAN   //使用WiFi网络
    
            }NetworkStatus;

     

    因此可以这样检查网络状态

     

    Reachability *r = [Reachability reachabilityWithHostName:@“www.apple.com”];
    
    switch([r currentReachabilityStatus])
    
    {
    
        case NotReachable:    //没有网络连接
    
           breakcase ReachableViaWWAN:  //使用3G网络连接
    
            break;
    
        case ReachableViaWiFi:    //使用WiFi网络
    
            break;
    
    }

    四、检查当前网络环境

      // 是否wifi

        + (BOOL) IsEnableWIFI {
            return ([[Reachability reachabilityForLocalWiFi] currentReachabilityStatus] != NotReachable);
        }



        // 是否3G
       

      + (BOOL) IsEnable3G {
            return ([[Reachability reachabilityForInternetConnection] currentReachabilityStatus] != NotReachable);
        }


        例子:

        - (void)viewWillAppear:(BOOL)animated {    
        if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) && 
                ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable)) {
                self.navigationItem.hidesBackButton = YES;
                [self.navigationItem setLeftBarButtonItem:nil animated:NO];
            }
        }

     

  • 相关阅读:
    删除文件夹右键下的部分目录
    c# datagridview导出到excel【转载】
    使用AO新增记录的3种方法【转载】
    AE 打包
    ArcMap 9使用技巧
    ArcEngine 渲染的使用【转载】
    关于数据库版本压缩
    SDE数据源直连
    ArcCatalog 9中的使用技巧
    AE指定字段转成注记
  • 原文地址:https://www.cnblogs.com/zhanggui/p/4503257.html
Copyright © 2011-2022 走看看