I want to check continuously for active internet connection.If internet is available, then some callback methods should be called or if internet is turned off then call back method should not be called.Please tell me how can i do this?
I have used below code to check if internet is available or not?
NotificationCenter.default.addObserver(self, selector: #selector(checkForReachability), name: ReachabilityChangedNotification, object: reachability)
do {
try reachability?.startNotifier()
}
catch {
DILog.print(items: "Error Occured")
}
func checkForReachability(notification:NSNotification) {
let networkReachability = notification.object as! Reachability;
let remoteHostStatus = networkReachability.currentReachabilityStatus
if (remoteHostStatus == .notReachable) {
DILog.print(items: "Not Reachable")
}
else if (remoteHostStatus == .reachableViaWiFi) {
DILog.print(items: "Reachable")
}
}