How to detect loss of internet reachability when wifi source loses connection?

后端 未结 3 1624
日久生厌
日久生厌 2021-02-04 16:10

I am trying hard to get the authentic internet connectivity status. I have used Apple\'s Reachability but it\'s only giving me the status of wifi connectivity i.e. not covering

3条回答
  •  执笔经年
    2021-02-04 16:39

    See Jordan's Answer. There is a stupid bug in Apple's official Reachability.m. The type for returnValue should be "NetworkStatus" instead of "BOOL":

    - (NetworkStatus)networkStatusForFlags:(SCNetworkReachabilityFlags)flags
    {
        ...
        NetworkStatus returnValue = NotReachable;
        ...
    }
    

    Otherwise, you end up with the following terrible consequences:

    1. Even if cellular connection is available, it will be reported as unavailable.
    2. If Wifi is unavailable, Wifi will be reported as available if cellular connection is available.

    Can't believe Apple never bothered to fix this.

    (P.S. New to stack overflow and have no reps to upvote Jordan)

提交回复
热议问题