My app is based on a TableView that download some data from a server using Alamofire. So because it's necessary to have an internet connection to use my app I want to check it continuously. I find a solution creating this class:
class Connectivity {
class func isConnectedToInternet() -> Bool {
return NetworkReachabilityManager()!.isReachable
}
}
And I add these lines of code in every method to check for Internet connection
if !Connectivity.isConnectedToInternet() {
print("No internet connection")
} else {
print("connected")
}
It works but I don't think that this is the right method to check continuously for the connection. I think that I've to implement some observer using notificationCenter from appDelegate but I don't know how to do it...