在didReceive中执行Segue接收响应:UNNotificationResponse

我是Swift的新手,正在尝试将其与Firebase推送通知集成。 推送通知本身工作正常,但是触摸通知时我很难打开特定的视图。

首先,我尝试通过InstantaiteViewController方法初始化根视图控制器,但是它不起作用 因此,我第二次尝试了当用户点击通知时是否可以从初始视图控制器执行segue。

第二个解决方案是我当前要实现的目标。 然后从UNUserNotificationCenterDelegate的“ didReceive响应:UNNotificationResponse”中调用perform segue方法

似乎正在执行segue。通过在目标ViewController的ViewDidLoad()ViewWillApear中打印字符串进行检查。

除非未显示其屏幕。 即使触发目标视图控制器ViewDidload,屏幕仍然显示初始视图控制器

这是关于生命周期的信息,还是根本无法做到这一点?

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 notification = response.notification
    if notification.request.trigger is UNPushNotificationTrigger{
        print("didRecieve Push Notification")
    }else{
        print("did Recieve Local Notification")
    }
    print("notification.requset.identifier: \(notification.request.identifier)")

    self.window = UIWindow(frame: UIScreen.main.bounds)
    let storyboard = uistoryboard(name:"Main",bundle: nil)
    print(storyboard)
    if let userShowCase = storyboard.instantiateViewController(withIdentifier:"userShowCase") as? userShowCaseViewController {
        print(storyboard)

        self.window?.rootViewController = userShowCase
        self.window?.makeKeyAndVisible()
        userShowCase.performSegue(withIdentifier: "showCase2Login",sender: userShowCase)

    }

    completionHandler()
}
panda__2001 回答:在didReceive中执行Segue接收响应:UNNotificationResponse

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3168745.html

大家都在问