首页 > 解决方案 > 不快速从应用程序委托重定向到另一个视图控制器

问题描述

我有一个推送通知,点击它,我需要重定向到另一个视图控制器而不是主视图控制器。我已经在应用程序委托方法中为它编写了代码。它不会重定向到提及情节提要名称的特定视图控制器。

 func userNotificationCenter(_ center: UNUserNotificationCenter,
                didReceive response: UNNotificationResponse,
                withCompletionHandler completionHandler:
                   @escaping () -> Void) {
        
        let userInfo = response.notification.request.content.userInfo
                  // Print message ID.
                  if let messageID = userInfo[gcmMessageIDKey] {
                      print("Message ID: \(messageID)")
                  }

                  // Print full message.
                  print(userInfo)
        let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let presentViewController = storyBoard.instantiateViewController(withIdentifier: "MessageViewController") as! MessageViewController

                
        self.window?.rootViewController?.present(presentViewController, animated: true, completion: nil)
     

        completionHandler()
}

它不会重定向到 MessageViewController,而是仅重定向到默认的主视图控制器。

上述代码中的错误可能是什么?

标签: swiftpush-notificationviewcontrollerappdelegate

解决方案


推荐阅读