【发布时间】:2020-01-10 04:40:35
【问题描述】:
在 iOS 13 之前,导航控制器和根视图是在 AppDelegate 中定义的。然而,在 iOS 13 中,Apple 引入了 SceneDelegate,它接管了这些视图功能的处理。但是,AppDelegate 仍然处理诸如本地通知处理之类的事情。 See this answer for some code that outlines these changes for root views.
如果我想在用户点击本地通知时推送视图,我会在 AppDelegate 中执行以下操作:
extension AppDelegate: UNUserNotificationCenterDelegate {
var navigationController: UINavigationController?
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if response.actionIdentifier == UNNotificationDefaultActionIdentifier { //User taps notification
let vc = MyViewController()
self.navigationController?.pushViewController(vc, animated: true)
}
}
}
但是,由于我的项目的根导航控制器现在可以在 iOS 13 中的 SceneDelegate 中定义,我似乎无法弄清楚如何在由 SceneDelegate 而不是 AppDelegate 管理的导航控制器中推送视图。
【问题讨论】:
-
我在同一条船上。在 AppDelegate 中,
window变量为零。我是否在SceneDelegate中设置窗口并在AppDelegate中使用它。