Мне нужно перейти к контроллеру уведомлений, когда пользователь нажимает на уведомление. Поэтому мне нужно перенаправить их из класса AppDelegate
Вот код:
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
if let cu = self.window?.rootViewController as? UITabBarController
{
print(cu)
let nav: UINavigationController = UINavigationController()
self.window?.rootViewController = nav
let str = UIStoryboard.init(name: "Main", bundle: nil)
let rr = str.instantiateViewController(withIdentifier: "NotificationListViewController")
nav.setViewControllers([cu,rr], animated: true)
}
}
// Print full message.
print(userInfo)
completionHandler()
}
}
Вышеприведенный метод работает, означает переход на страницу уведомлений только в первый раз, когда я пытаюсь со вторым разом перейти на страницу панели инструментов.
Условие if не выполняется во второй раз (получение нулевого значения).
Помогите мне, если кто-то знает