【发布时间】:2020-12-24 21:36:18
【问题描述】:
当点击包含“主页”类别的通知时,我正在尝试将我的根 ViewController 切换到我的 HomeViewController。自从添加了 SceneDelegate 后,我在从 AppDelegate 转换 ViewController 时遇到了困难。
我的 AppDelegate,使用故事板 Swift 5 和 Xcode 11.6
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("Handle push from background or closed")
print("user clicked on the notification")
let userInfo = response.notification.request.content.userInfo
let categoryValue = userInfo["category"] as? String ?? "0"
if categoryValue == "Home"
{
print("Switching to Home!")
//change ViewController here
}
}
}
感谢您的帮助!
【问题讨论】:
-
不清楚是什么问题。你的代码能运行吗?是否打印“切换到主页”?还是您不知道如何从应用代理与场景代理对话的问题?
-
是的,代码运行良好,问题在于以编程方式切换视图控制器。像这样的东西是我需要的,但我找不到一种方法让它从 appdelegate 工作: self.view.window?.rootViewController = homeViewController self.view.window?.makeKeyAndVisible() 问题是与场景委托交谈来自应用委托。
标签: ios swift firebase uiviewcontroller swift5