Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reachability only ever called once, not changing after! #216

Closed
nadimalam opened this issue Jul 27, 2017 · 7 comments
Closed

Reachability only ever called once, not changing after! #216

nadimalam opened this issue Jul 27, 2017 · 7 comments

Comments

@nadimalam
Copy link

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.

@ashleymills
Copy link
Owner

See issues #93, #85, #144

@nadimalam
Copy link
Author

@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

@nadimalam
Copy link
Author

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.

@nadimalam
Copy link
Author

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

thanks

@lloydroc
Copy link

lloydroc commented Aug 5, 2017

Ate you anywhere perhaps stopping the notifier?

@lloydroc
Copy link

lloydroc commented Aug 5, 2017

Or removing the observer?

@nadimalam
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants