Created
October 1, 2022 11:20
-
-
Save ponnamkarthik/db50dd16ff8d1fa0643b74172caa2338 to your computer and use it in GitHub Desktop.
ios UIApplication extension function to get the UIViewController in flutter plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIApplication { | |
class func topViewController(controller: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? { | |
if let navigationController = controller as? UINavigationController { | |
return topViewController(controller: navigationController.visibleViewController) | |
} | |
if let tabController = controller as? UITabBarController { | |
if let selected = tabController.selectedViewController { | |
return topViewController(controller: selected) | |
} | |
} | |
if let presented = controller?.presentedViewController { | |
return topViewController(controller: presented) | |
} | |
return controller | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment