Currently I implemented the Reachability is AppDelegate.swift file. This is my code to determine when I connect or disconnect to the internet
@objc func reachabilityChanged(note: Notification) {
let reachability = note.object as! Reachability
if (reachability.connection != .none) {
}
else
{
currentView()
}
}
This code works fine to detect if the internet is connected or disconnected. Now if the internet is disconnected I want to know which viewController I am currently at in my navigationController and I would like to modify the UI of that viewController to notify the user that the Internet Is disconnected. I am trying to get the current viewController in my navigationStack using the following code but it does not work
if let window = UIApplication.shared.delegate?.window {
if var viewController = window?.rootViewController {
// handle navigation controllers
if(viewController is UINavigationController){
viewController = (viewController as! UINavigationController).visibleViewController!
}
print (viewController)
}
}