ios - 单击用户通知时直接进入特定 View

标签 ios swift push-notification uinavigationcontroller uinavigationbar

我已经在我的项目中实现了推送通知,点击推送通知(在非事件、后台和前台模式)时,我将用户从 appdelegate 引导到特定的 Viewcontroller,其中有通知列表,这里是代码:

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse,withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
 if let messageID = userInfo[gcmMessageIDKey] {
                    print("Message ID: \(messageID)")
                }
   let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                        let initialViewController: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "VANotificationTableViewController") as! VANotificationViewController

                        self.window = UIWindow(frame: UIScreen.main.bounds)
                        self.window?.rootViewController = initialViewController
                        self.window?.makeKeyAndVisible()
                //showPushNotification(message: response.notification.request.content.body)

                completionHandler()
            }

基本上,我将通知 View Controller 作为我的 rootViewController 单击通知 View Controller 中的后退按钮时,它应该向我显示仪表板 View Controller ,但仪表板 View Controller 顶部没有通知栏。 我尝试过的事情

  • self 解雇
  • 尝试过转场
  • 通过通知 View Controller 上的后退操作将仪表板 Controller 设置为 Root View Controller

    有没有办法让我可以以不同的方式将 View 从 AppDelegate 导航到通知 ViewController,以便代码正常工作?

最佳答案

 func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse,withCompletionHandler completionHandler: @escaping () -> Void) {
    let userInfo = response.notification.request.content.userInfo
    if let messageID = userInfo[gcmMessageIDKey] {
        print("Message ID: \(messageID)")
    }
    let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let initialViewController: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "VANotificationTableViewController") as! VANotificationViewController
    let nav  = UINavigationController.init(rootViewController: initialViewController)
    self.window = UIWindow(frame: UIScreen.main.bounds)
    self.window?.rootViewController = nav
    self.window?.makeKeyAndVisible()
    //showPushNotification(message: response.notification.request.content.body)
    completionHandler()}

关于ios - 单击用户通知时直接进入特定 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52873079/

相关文章:

c++ - 作为可选函数指针的类参数不被识别为函数

ios - 使用 Sinch 的即时消息推送通知未在 iOS 上提供

php - 社交 Android 应用程序的通知系统 - 推送与轮询以及如何制作服务器 "Push"

ios - IOS 上的 Safari 中每个域允许多少个同时 websocket 连接?

iOS:上传到 Facebook 的照片并不总是上传

ios - 在横向模式下,背景颜色仅出现在屏幕的一半上

ios - 删除单行解析

swift - CLLocationManager didUpdateLocations 在后台模式下仅被调用两次

ios - 如何在 swift 中为 Messenger 应用程序实现 "istyping"?

ios - 对每个 Collection View 单元格使用单个 TableView Controller