Reachability.swift icon indicating copy to clipboard operation
Reachability.swift copied to clipboard

Reachability doesn't detect reconnection in iOS 10 devices

Open amit3609 opened this issue 7 years ago • 17 comments

Steps:

  1. Disconnect internet connection(LAN cable) from WIFI router, but keep WIFI running. -> reachabilityChanged function called after 3 to 15 minutes(approx).

  2. 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.

amit3609 avatar Jun 27 '17 10:06 amit3609

Seems to also be the case for me.

markst avatar Jun 29 '17 12:06 markst

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

jainricha avatar Jul 04 '17 06:07 jainricha

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

ashleymills avatar Jul 04 '17 15:07 ashleymills

@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.

amit3609 avatar Jul 05 '17 05:07 amit3609

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?

lloydroc avatar Aug 07 '17 04:08 lloydroc

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 avatar Dec 05 '17 21:12 jlstr

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

ashleymills avatar Dec 06 '17 12:12 ashleymills

@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

jlstr avatar Dec 06 '17 15:12 jlstr

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 avatar Dec 06 '17 15:12 ashleymills

@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,

jlstr avatar Dec 07 '17 14:12 jlstr

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

fphilipe avatar Dec 19 '17 06:12 fphilipe

I am having the same issue here. Any ideas?

BorisNikolic avatar Jun 14 '18 11:06 BorisNikolic

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

ahegazi18 avatar Oct 11 '18 08:10 ahegazi18

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

ashleymills avatar Oct 11 '18 09:10 ashleymills

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

lambaosk8 avatar Oct 29 '18 07:10 lambaosk8

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 avatar Feb 13 '19 07:02 codenameDuchess

@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()
    }
}

jarrodparkes avatar Oct 04 '19 20:10 jarrodparkes