应用启动时如何显示警报

编程入门 行业动态 更新时间:2024-10-13 12:19:41
本文介绍了应用启动时如何显示警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在当天首次启动我的应用程序时发出警报. 我认为执行此操作的地方是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) } }

更多推荐

应用启动时如何显示警报

本文发布于:2023-11-27 22:04:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639771.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   启动时

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!