2016-02-27 82 views
-1

我想在當天第一次啓動應用程序時顯示提醒。 我認爲做這個的地方是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???? 
    } 

我應該更換什麼代碼的註釋?

回答

1

嘗試使用此梅索德: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) 
    } 
} 
相關問題