在我的应用程序中,我有三个视图控制器,让我们称它们为MainVC,ObjectsVC和EventsVC(如果你不喜欢这样的快捷方式,那就很抱歉)。 MainVC是整个应用程序的初始VC,其余的是包含带有一些对象的列表的TableVC
此应用程序支持随附的推送通知" id"现场:
- id = 0 - > app正常启动
- id = 1 - >应用程序以ObjectsVC开始
- id = 2 - >应用程序以EventsVC开始
当用户点击传入的PN时,如何实现上面列出的转换?
答案 0 :(得分:2)
一种简单的方法是返回初始viewController
,然后推送所需的方法。例如:
if id == 2 {
let eventsVc = EventsVC()
navigationController?.popToRootViewController(animated: false)
navigationController?.pushViewController(eventsVc, animated: false)
}
如果所需的viewController
已经在导航堆栈中,您应该检查它是否真的存在并pop
。
这实际上取决于所需的导航行为。
答案 1 :(得分:0)
尝试使用
(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler;
您可以通过notification.request.content.userInfo
获取notificationId