• 检测是否在Wifi环境下,写成单例判断


    #import <Foundation/Foundation.h>

    #import "ASIFormDataRequest.h"

    #import "Reachability.h"

    @interface HttpHelper : NSObject

    {

        Reachability* internetReach;

    NetworkStatus netStatus;

    }

    + (id) sharedHttpHelper;

    - (BOOL)checkIsWifi;

    @end

     ///////// ///////// ///////// ///////// ///////// ///////// ///////// ///////// ///////// ///////// ///////// ///////// ///////// ///////// 

    #import "HttpHelper.h"

    @implementation HttpHelper

    static HttpHelper *_sharedInst = nil;

    //

    + (id) sharedHttpHelper

    {

    @synchronized(self){

    if(_sharedInst == nil)

    {

    _sharedInst = [[self alloc] init];

    }

    }

    return_sharedInst;

    }

    -(id) init

    {

    if (self = [super init]) {  

    //通知 (网络状态变化)

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

    internetReach = [[ReachabilityreachabilityForInternetConnection]retain];

    [internetReachstartNotifier];

    netStatus = [internetReachcurrentReachabilityStatus];

    }

    returnself;

    }

     //检测网络是否在WiFi条件下

    - (BOOL)checkIsWifi//检测是否在wifi下

    {

        if (netStatus == ReachableViaWiFi) {//网络状态是否是wifi下,如果是返回YES

            return YES;

        }

        returnNO;

    }

    - (void) reachabilityChanged: (NSNotification* )note

    {

    netStatus = [internetReachcurrentReachabilityStatus];

    }

    @end

  • 相关阅读:
    第五周作业
    2019春第四周作业编程总结
    2019春第四周作业
    2019春第二周作业编程总结
    2019春第一周作业编程总结
    自我认识
    对我影响最大的三位老师
    C语言I博客作业04
    C语言I博客作业03
    C语言I博客作业02
  • 原文地址:https://www.cnblogs.com/leevaboo/p/3230451.html
Copyright © 2020-2023  润新知