Networker
library helps to check network status with simple 5 steps.
Just subscribe for network notifications, that all you will get an update when there is a change in 'Network' status.
import Networker
ViewController
let reachability = Networker.shared
viewDidLoad()
override func viewDidLoad() {
super.viewDidLoad()
reachability.register()
Notification.Name.didUpdateNetworkStatus.add(self,
selector: #selector(networkStatusChanged),
object: nil)
}
networkStatusChanged
method in your ViewController
@objc func networkStatusChanged() {
switch reachability.currentStatus {
case .reachableViaWWAN, .reachableViaWiFi:
print(" ✅ Network status 'Connected'")
// Do your stuff here code 💻💻💻
case .notReachable:
print("❗️Network status 'No Internet'")
}
}
deinit()
deinit {
Notification.Name.didUpdateNetworkStatus.remove(self)
}
link |
Stars: 3 |
Last commit: 3 years ago |
Creating the latest version with updated code.
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics