Search code examples
iosipautomatic-ref-countingip-addressreachability

Why reachability of IP address never gets called back?


I've been struggling for two days for now with this. https://stackoverflow.com/questions/17077345/reachability-of-ip-address


Finally I found a solution, so if anyone had the same problem, see the answer below.


Solution

  • After days of research, I found a solution. The bottleneck is to invoke the current reachability status even in "listening" mode, when initialized with an IP adddress (like the one snippet below, without the rest application context).

    if (isAddressReachability)
    {
        dispatch_async(dispatch_queue_create("com.eppz.reachability.workaround", NULL), ^
        {
            SCNetworkReachabilityFlags flags;
            if (SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags))
            {
                //'Manual' invocation of callback functionality.
                dispatch_async(dispatch_get_main_queue(), ^ //Dispatch delegate callback on the main thread.
                {
                    [self parseFlags:flags];
                    [self.delegate reachabilityChanged:self];
                });
            }
        });
    }
    

    More detailed at: http://eppz.eu/blog/reachability-with-ip-address-doesnt-work/