Reachability.swift: Reachability doesn't detect reconnection in iOS 10 devices

Created on 27 Jun 2017  Â·  17Comments  Â·  Source: ashleymills/Reachability.swift

Steps:

  1. Disconnect internet connection(LAN cable) from WIFI router, but keep WIFI running. -> reachabilityChanged function called after 3 to 15 minutes(approx).
  1. Plugged-in the LAN cable into WIFI router and wait for long time (1 hour approx) but reachabilityChanged function is not called few times with iOS 10 devices.

Any advice appreciated.

Most helpful comment

This only happens to me on the simulator. Running it on my iPhone does not show this behavior and works as intended.

All 17 comments

Seems to also be the case for me.

@ashleymills Is there any update on this issue? I also face the same issue, Please look into this.

Is this on simulator or device? Which (exact iOS version)? Does it happen every time?

@ashleymills We are at present facing this issue in multiple device and iOS 10.
To mention a few:



  • iPhone 7 plus (iOS v10.2)
    
- iPhone 5S (iOS 10.x)
    It is not reproducible every time, but very often.

Is this really in the scope of reachibility? In this case the phone is able to reach the LAN but not the WAN right? Technically a LAN connection is reachable. Can't reachibility only know what iOS gives it? In this case did your app attempt to make a connection in the 3-15 min to anything where iOS could determine requests aren't routable?

Hello there,

I have just started testing this Pod in the Simulator (iOS 11) and I've noticed that it works for the case of Network Loss.

disconnect

But the reachability?.whenReachableclosure isn't called when I reconnect the Network.

connect

Is this expected behavior for the simulator? Or will it also be an issue when deployed to a real device?

This is the code I'm using inside my ViewController:

var reachability: Reachability?

override func viewWillAppear(_ animated: Bool) {   
  super.viewWillAppear(animated)
  reachability = Reachability()!

  reachability?.whenReachable = { reachability in
    print("Online!") // Only Works Once!
  }

  reachability?.whenUnreachable = { _ in
    print("Network Connection Lost!")  // Works!
  }

  do {
    try reachability?.startNotifier()
  } catch {
    print("Unable to start notifier")
  }
}

Thanks in advance!

@jlstr Can you please try the sample app and confirm the behaviour is the same?

@ashleymills Hello there!

Thank you very much for the response, sir. I have tried the sample code and it works, however, I did notice that it works only because in it a recursive call is made to the function that sets up Reachability over and over. I had hoped that I would only have to configure it once, and then have the Closures act accordingly (That is, to listen to Network changes without reconfiguration). Is it possible? or is the loop inevitable?

Regards,
-Jose

The loop isn't required - that's just there to cycle through various hosts. Try removing the

        DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
            self.startHost(at: (index + 1) % 3)
        }

and see if it still works

@ashleymills I'm afraid not, sir. It still does not work. As I mentioned before, it only detects the initial disconnection, but subsequent events are not detected. Do you have a minimalistic example around that you can show us? One that you have certified to be working? Maybe I screwed up the Sample in the Repo, I can't be entirely sure.

Kind Regards,

This only happens to me on the simulator. Running it on my iPhone does not show this behavior and works as intended.

I am having the same issue here. Any ideas?

I am also having the same issue in both real device and simulator

Please confirm that you’re having the same problem with the sample app

@ashleymills I confirm that Sample App have the same issue when I remove host changing loop

Found I was having this issue when instantiating a member variable once and reusing it. After internet connection restored the reachability variable still reported it had no internet connection. But if I used a fresh instance variable each time I need to check the connection this issue does not occur.

   if let reachability = Reachability(), reachability.connection == .none {
        //no internet
    } else {
        //internet
    }

Hope this helps someone else.

@codenameDuchess solution worked for me too. used something like this

// ...call checkNetworkSignal()...

func checkNetworkSignal() {
    DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
        if let reachability = Reachability(hostname: "google.com"), 
            reachability.connection == .none {
            // not connected
        } else {
            // connected
        }

        self.checkNetworkSignal()
    }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

antonys1 picture antonys1  Â·  6Comments

mohamamdkalim picture mohamamdkalim  Â·  17Comments

X901 picture X901  Â·  5Comments

AlekseiR picture AlekseiR  Â·  4Comments

tjarbo picture tjarbo  Â·  12Comments