Swift 如何在应用程序启动时显示警报
我想在当天我的应用程序首次启动时发出警报。 我认为这样做的地方是appDelegate(如果我错了,请纠正我)。我有两个问题,一个是:我不知道该函数应该驻留在appDelegate中的哪个函数下(目前只选择了func应用程序),第二个是:我不知道如何向打开的视图显示alertController。到目前为止,我已经做到了这一点Swift 如何在应用程序启动时显示警报,swift,launch,uialertcontroller,Swift,Launch,Uialertcontroller,我想在当天我的应用程序首次启动时发出警报。 我认为这样做的地方是appDelegate(如果我错了,请纠正我)。我有两个问题,一个是:我不知道该函数应该驻留在appDelegate中的哪个函数下(目前只选择了func应用程序),第二个是:我不知道如何向打开的视图显示alertController。到目前为止,我已经做到了这一点 func application(application: UIApplication, didFinishLaunchingWithOptions launchOpti
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????
}
我应该用什么代码替换注释?尝试使用此方法:
applicationdibecomeactive
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)
}
}
尝试使用此方法:
applicationIDBecomeActive
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)
}
}