みんな!DidReceiveLocalNotificationのアラートハンドラ/クロージャでVCからメソッドを追加する方法?
私のアプリがフォアグランドで、DidReceiveLocalNotificationがトリガーされたときに警告を表示したいとき。
AppDelegate.swiftの模擬ローカル通知にアラートを追加することはできますが、タイマー停止時にアニメーションを終了するには、ViewControllerからUIAlertActionクロージャ(コメント行参照)にメソッドを追加する方法がわかりません。
以下の私のコード:
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
let alertTimerEnds = UIAlertController(title: "Timer finished!", message: nil, preferredStyle: .Alert)
let okAction = UIAlertAction(title: "OK", style: .Default) { finished in
print("You've pressed OK button")
//self.ViewController().finishAnimation()
}
alertTimerEnds.addAction(okAction)
self.window?.rootViewController?.presentViewController(alertTimerEnds, animated: true, completion: nil)
}
たぶん私はViewControllerをusind AppDelegateでそれを行う必要がありますか?
let someAppDelegate = UIApplication.sharedApplication().delegate as? AppDelegate
someAppDelegate?.application(UIApplication.sharedApplication(), didReceiveLocalNotification: UILocalNotification) { code for alert }
あなたがlocalnotificationをタップしたときにのみdidReceiveLocalNotification呼び出しを知っていますか?正確に何をしたいですか? – Hasya
@ハシャそれについては知らなかった。私のコードが働き、アプリケーションがフォアグラウンドで通知を受け取ったときに警告を表示します。少なくともシミュレータで。 問題は、このアラートでメソッドを使用してアニメーションを終了することです。コメント行を参照してください。このメソッドはメインViewControllerにあります。 私の友人はappdeleageteでNSNotificationを使用することを提案し、ViewControllerはこの特定のNSNotificationに反応するようにチューニングする必要があります。後で試してみる。 – odvan
誰でも私の質問に編集できないのですか? – odvan