我想在我的应用程序当天第一次启动时发出提醒。 我认为这样做的地方是appDelegate(如果我错了,请纠正我)。我有两个问题,一个:我不知道该函数应该驻留在appDelegate中的哪个函数(目前只选择了func应用程序),第二个:我不知道如何将alertController呈现给视图开了。到目前为止,我已经完成了这个
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????
}
我应该用什么代码替换注释?
答案 0 :(得分:2)
尝试使用此方法: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)
}
}