本文介绍了应用启动时如何显示警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在当天首次启动我的应用程序时发出警报. 我认为执行此操作的地方是appDelegate(如果我输入错误,请纠正我).我有两个问题,一个是:我不知道该功能应该驻留在appDelegate中的哪个函数(当前已选择仅是func应用程序),第二个:我不知道如何向视图呈现alertController开了.到目前为止,我已经做到了
I want to present an alert when my app launches for the first time that day. I think the place to do this is the appDelegate (correct me if i am wrong). I have two problems, one: i don't know which of the functions in the appDelegate the function should reside under (have currently chosen just func application), and second: i don't know how to present the alertController to the view that is open. Thus far i have done this
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { if checkIfNewDay() { let alert = UIAlertController("some title": alertTitle, message: "some message", preferredStyle: .Alert) alert.addAction(UIAlertAction(title: "Okay", style: .Cancel, handler: nil)) // What to do here???? }我应该用什么代码替换注释?
What code should i replace the comment with?
推荐答案尝试使用此方法:applicationDidBecomeActive
func applicationDidBecomeActive(application: UIApplication) { //This method is called when the rootViewController is set and the view. if checkIfNewDay() { let alert = UIAlertController("some title": alertTitle, message: "some message", preferredStyle: .Alert) alert.addAction(UIAlertAction(title: "Okay", style: .Cancel, handler: nil)) self.window?.rootViewController?.presentViewController(alert, animated: true, completion: nil) } }更多推荐
应用启动时如何显示警报
发布评论