Для состояния убийства ИЛИ состояния завершения:
Определить новое свойство в AppDelegate.swift файл
var isFromNotification = false
Внести следующие изменения в AppDelegate.swift и оставьте остаток кода таким, какой он есть.
if launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] != nil {
isFromNotification = true
//other required code
}
Перейдите на Homepage.swift файл
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated).
let appDelegate = UIApplication.shared.delegate as! AppDelegate
if appDelegate.isFromNotification {
appDelegate.isFromNotification = false
//Push to your notification controler without animation
}
}
Обновление: для фона и состояния переднего плана
Вышеуказанный ответ относится только к состоянию убийства, как упомянуто в комментарии @ Абу Уль Хассан
Теперь давайте разберемсяпоток о состоянии фона или переднего плана.
userNotificationCenter (_: didReceive: withCompletionHandler:) метод вызывается, когда пользователь нажимает на уведомление в фоновом режиме или в режиме переднего плана.
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
//other required code
//Get current navigation controller and redirect into notification screen
completionHandler()
}
Как получить текущий UIViewController или текущий UINavigationController
Пожалуйста, отметьте как принятый, если работал.
Спасибо