【问题标题】: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

   }

【问题讨论】:

标签: ios swift notifications


【解决方案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
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-04
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 2017-01-13
    • 1970-01-01
    相关资源
    最近更新 更多