2017-07-12 8 views
0

UserNotificationsを実装したLocalNotificationクラスがあります。私は最初のViewControllerと私が提示する必要があるCheckViewControllerの間にsegueを作成しました。それは私のdidReceive responce FUNCUserNotificationsを使用してViewControllerを提示しました。受信しました

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) { let storyboard = UIStoryboard(name: "Main", bundle: nil) let nav = storyboard.instantiateInitialViewController() as! UINavigationController let mainViewController = nav.topViewController as! ViewController mainViewController.performSegue(withIdentifier: "CheckSegue", sender: nil) }

しかし、まだだ私が得るすべては - 初期のViewControllerです。どこが間違っていますか?

答えて

1

MainViewControllerイニシャルビューコントローラですか?その場合、表示されるインスタンスはアプリケーションのルートです。表示されない全く新しいインスタンスを作成しています。

let nav = UIApplication.shared.keyWindow?.rootViewController as? UINavigationController 

代わりの

let nav = storyboard.instantiateInitialViewController() as! UINavigationController 
+0

それは作品をお試しください!ありがとう – L1GhTUA

+0

しかし、私は最初のビューではない場合はエラーが発生している – L1GhTUA

+0

ええ、おそらく最初のビューに戻って、これが動作するためにナビゲートする必要があります - 多分、最初のビューに戻ってから、セグを実行しますか? – Samantha

関連する問題