如何在通知操作中显示特定的viewcontroler?

时间:2017-08-29 03:11:01

标签: ios swift notifications

如何在通知操作中显示特定的viewcontroler? 在appdelegate

func usernotificationcenter(_center: UNUserNotification,didReceive response: UNNotificationPesponse,withCompletionHalndler completion Handler: @escaping () -> Void){ 

   if identifer == "SHOWVIEW_ACTION":
                //I want show specific viewController at this

   }

2 个答案:

答案 0 :(得分:0)

在确实收到回复中添加这些代码行,它对我有用

 let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let navigationController = self.window?.rootViewController as? UINavigationController
    let destinationController = storyboard.instantiateViewController(withIdentifier: "YourIdentifierName") as? YourViewController
    navigationController?.pushViewController(destinationController!, animated: false)
var presentedVC = self.window?.rootViewController
        while (presentedVC!.presentedViewController != nil)  {
            presentedVC = presentedVC!.presentedViewController
        }

答案 1 :(得分:0)

func redirectToSpecificVC() {
let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "versesVC") as UIViewController
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()}

使用这些函数重定向到特定的视图控制器