gpt4 book ai didi

ios - Swift didReceiveRemoteNotification - 无论应用用户位于何处,都导航到 rootviewcontroller(现在有错误消息)

转载 作者:行者123 更新时间:2023-11-28 09:12:46 26 4
gpt4 key购买 nike

在 IOS Swift 应用程序中收到推送通知后,我想根据通知中的内容做两件事:

  1. 要么导航到屏幕(深层链接),这样我就必须从 rootviewcontroller 导航到多个屏幕。

  2. 无论用户位于应用中的哪个位置,都导航到 rootviewcontroller。

我认为第二个是第一个的先决条件。

我知道我需要在这两个函数中放置代码:

  • didReceiveRemoteNotification
  • didReceiveLocalNotification

错误信息:“UIViewcontroller?”没有名为“navigationController”的成员

在 AppDelegate.swift 文件中:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) 
{
println("didReceiveRemoteNotification")
//Navigate to rootviewcontroller
var rootViewController = self.window!.rootViewController
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var setViewController = mainStoryboard.instantiateViewControllerWithIdentifier("CurrentShows")
as ViewController

//rootViewController.navigationController?
// .popToViewController(setViewController, animated: false)
}

最佳答案

在你的方法中尝试这段代码:

var rootViewController = self.window!.rootViewController
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

var setViewController = mainStoryboard
.instantiateViewControllerWithIdentifier("CurrentShows")
as ViewController_CurrentShows

rootViewController
.navigationController
.popToViewController(setViewController, animated: false)

关于ios - Swift didReceiveRemoteNotification - 无论应用用户位于何处,都导航到 rootviewcontroller(现在有错误消息),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28673151/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com