跳到主要內容

[Swift] 在AppDelegate取得正顯示的ViewController

//取得正顯示的ViewController
let navigationController = application.windows[0].rootViewController as! UINavigationController
let activeViewCont = navigationController.visibleViewController

//顯示Alert
var alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "關閉", style: UIAlertActionStyle.Default, handler: nil))
activeViewCont.presentViewController(alert, animated: true, completion: nil)

留言