Using Reachability for Internet *or* local WiFi?

前端 未结 4 502
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-19 00:37

I\'ve searched SO for the answer to this question, and it\'s not really addressed, at least not to a point where I can make it work.

I was originally only checking f

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-19 00:41

    Use this function to check if wifi is on

    - (BOOL)isWifiOn {
        Reachability* wifiReach = [Reachability reachabilityForLocalWiFi];
    
        NetworkStatus netStatus = [wifiReach currentReachabilityStatus];
        return (netStatus==ReachableViaWiFi);
    }
    

    similar code can be used to check reachabilityForInternetConnection but you have to check

    (netStatus==ReachableViaWiFi)
    

    if you care that it's over wifi AND

    (netStatus==ReachableViaWWAN)
    

    if you care that it's over WWAN

提交回复
热议问题