Reachability.swift: Reachability only ever called once, not changing after!

Created on 27 Jul 2017  Â·  7Comments  Â·  Source: ashleymills/Reachability.swift

Hi,

Im using the closures example on the wiki.

Im using the simulator, I've tried in both iPhone 7 plus and iPhone 7.

I start my app with network enabled, close the network wifi down, it catches it as its supposed to.

However, i then turn the wifi back on and reachability still shows up as being Not Reachable.

Basically none of the closures are ever called again after the first time.

Any help with this please?

Thanks.

Most helpful comment

Sorry forgot to update this, yeah actually it was working fine. The only issue was that i was testing on the simulator and turning the macbooks wifi connection off, for some reason it doesnt work on simulator properly and only calls the closure functions once each.

Testing it on a device solved all the issues :)

thanks

All 7 comments

See issues #93, #85, #144…

@ashleymills thank you for your response, I've had a look at those but still can't get it to work. I believe I'm doing it exactly the same as those examples and solutions. Not sure why its not working for me or what I'm missing.

var reachability = Reachability()!

    override func viewDidAppear(_ animated: Bool) {
        connectionCheck()
    }
    func connectionCheck()
    {
        reachability.whenReachable = { reachability in

            // this is called on a background thread, but UI updates must
            // be on the main thread:
            DispatchQueue.main.async {
                print("Reachable via internet")
                self.crToastShowNotification(show: false)
            }
        }

        reachability.whenUnreachable = { reachability in

            // this is called on a background thread, but UI updates must
            // be on the main thread:
            DispatchQueue.main.async {
                print("Not reachable")
                self.crToastShowNotification(show: true)
            }
        }

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

Can you spot anything that I'm missing? Thanks

Ive tried everything, just can't get it to work :(

Both closures fire off once only! After that never again. I have also declared: var reachability = Reachability()! outside the functions and at the top of the class.

Please can you @ashleymills or anyone help me with this? As i have no idea what else to try.

thanks

Ate you anywhere perhaps stopping the notifier?

Or removing the observer?

Sorry forgot to update this, yeah actually it was working fine. The only issue was that i was testing on the simulator and turning the macbooks wifi connection off, for some reason it doesnt work on simulator properly and only calls the closure functions once each.

Testing it on a device solved all the issues :)

thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

samuelbeek picture samuelbeek  Â·  3Comments

hvsw picture hvsw  Â·  4Comments

rjt3662 picture rjt3662  Â·  3Comments

cannyboy picture cannyboy  Â·  9Comments

dave212 picture dave212  Â·  3Comments