我已经在我的项目中实现了推送通知,点击推送通知(在非事件、后台和前台模式)时,我将用户从 appdelegate 引导到特定的 Viewcontroller,其中有通知列表,这里是代码:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse,withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "VANotificationTableViewController") as! VANotificationViewController
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
//showPushNotification(message: response.notification.request.content.body)
completionHandler()
}
基本上,我将通知 View Controller 作为我的 rootViewController 单击通知 View Controller 中的后退按钮时,它应该向我显示仪表板 View Controller ,但仪表板 View Controller 顶部没有通知栏。 我尝试过的事情
- self 解雇
- 尝试过转场
通过通知 View Controller 上的后退操作将仪表板 Controller 设置为 Root View Controller
有没有办法让我可以以不同的方式将 View 从 AppDelegate 导航到通知 ViewController,以便代码正常工作?
最佳答案
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse,withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "VANotificationTableViewController") as! VANotificationViewController
let nav = UINavigationController.init(rootViewController: initialViewController)
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = nav
self.window?.makeKeyAndVisible()
//showPushNotification(message: response.notification.request.content.body)
completionHandler()}
关于ios - 单击用户通知时直接进入特定 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52873079/