Isuru-Nanayakkara / Reach

A simple class to check for internet connection availability in Swift.
MIT License
456 stars 119 forks source link

Notifications did not work as expected. #26

Open danilamaster opened 4 years ago

danilamaster commented 4 years ago

Little experiment on XCODE 11.5

Add Reach.swift to project

Add code

NotificationCenter.default.addObserver(self, selector: #selector(ViewController.networkStatusChanged(_:)), name: Notification.Name(rawValue: ReachabilityStatusChangedNotification), object: nil)
        Reach().monitorReachabilityChanges()

to viewDidLoad() of ViewController


Turn Network Off unplugging net cable and switch off Wi-Fi connection on Mac

Build and start project in Simulator

We get string "Offline" on output. Everything is fine right now.

Switch internet connection On connecting to WiFi. Run some net activity in project. Download some data successfully. Nothing happen in NotificationCenter about ReachabilityStatusChangedNotification.


Another scenario with same code.

Turn Network On unplugging net cable but switch Wi-Fi connection On

Build and start project in Simulator

We get string "Online" on output. Everything is fine right now. Switch Wi-Fi off. We get string "Offline" on output. Everything is perfect! But Reconnect Wi-Fi. Run some net activity in project. Download some data successfully. Ooops. Nothing happen in NotificationCenter about ReachabilityStatusChangedNotification again.

danilamaster commented 4 years ago

On real device all works fine after turning router on/off.