Swift-如何在没有情节提要的情况下在userNotificationCenter中推送ViewController
我正在用Firebase实现推送通知功能 对于最后一部分,我想在点击通知时创建一个指向NavigationController页面的链接Swift-如何在没有情节提要的情况下在userNotificationCenter中推送ViewController,swift,Swift,我正在用Firebase实现推送通知功能 对于最后一部分,我想在点击通知时创建一个指向NavigationController页面的链接 func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
var parentController: UINavigationController?
let destinationVC = SomeNavigationController()
let userInfo = response.notification.request.content.userInfo
if let maeesageId = userInfo["maeesageId"] as? String {
destinationVC.maeesageId = maeesageId
parentController?.navigationController?.pushViewController(destinationVC, animated: true)
}
}
使用这些代码,当我点击一个通知时,它不会崩溃,但会将我带到一个rootViewController页面
如何实现此功能?在您的
rootViewController
中,设置一个布尔标志,以检查它是否由推送通知显示。如果是,导航到视图中的下一个视图控制器将显示根视图控制器的
class RootViewController: UIViewController {
var isPresentedByPushNotification = false
override viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if isPresentedByPushNotification {
//Set the flag to false so that you don't end up in a loop
//when you press back on the next view controller
isPresentedByPushNotification = false
//Navigate to the next view controller here
}
}
}
当您收到通知时,在按下destinationVC
之前,将标志设置为true
destinationVC.isPresentedByPushNotification = true
你的意思是你想导航到导航堆栈中较低的一个页面吗?是的,我想这就是我想要的do@coonieu r移动到嵌入选项卡栏的ViewController