如何在通知操作中显示特定的视图控制器?
Posted
技术标签:
【中文标题】如何在通知操作中显示特定的视图控制器?【英文标题】:how can i show specific viewcontroler in notification action? 【发布时间】:2017-08-29 03:11:00 【问题描述】:在应用程序中
func usernotificationcenter(_center: UNUserNotification,didReceive response: UNNotificationPesponse,withCompletionHalndler completion Handler: @escaping () -> Void)
if identifer == "SHOWVIEW_ACTION":
//I want show specific viewController at this
【问题讨论】:
Dismiss and Present View Controller in Swift的可能重复 【参考方案1】:func redirectToSpecificVC()
let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "versesVC") as UIViewController
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
使用这些函数重定向到特定的视图控制器
【讨论】:
instantiateViewController(withIdentifier: "versesVC") 什么是 versecvc?故事板ID?还是恢复id? 这是故事板ID 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“在捆绑 NSBundl 中找不到名为“alarmRing”的情节提要有什么问题??我确实在 Storyboard Id 处输入了 alarmRing【参考方案2】:在确实收到响应中添加这些代码行,它对我有用
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let navigationController = self.window?.rootViewController as? UINavigationController
let destinationController = storyboard.instantiateViewController(withIdentifier: "YourIdentifierName") as? YourViewController
navigationController?.pushViewController(destinationController!, animated: false)
var presentedVC = self.window?.rootViewController
while (presentedVC!.presentedViewController != nil)
presentedVC = presentedVC!.presentedViewController
【讨论】:
以上是关于如何在通知操作中显示特定的视图控制器?的主要内容,如果未能解决你的问题,请参考以下文章
当点击 FCM 推送通知时,如何在选项卡栏中打开特定的视图控制器?