didReceiveRemoteNotification Не работает при нажатии на уведомление (фон), но при работе, когда приложение находится на переднем плане - PullRequest
2 голосов
/ 14 февраля 2020

Нужны некоторые решения относительно уведомлений PU SH. Я пробовал разные решения из стека, но у меня не получалось!

Моя проблема в том, что когда я запускал уведомление из моего PHP сценария , само уведомление запускалось. После нажатия на уведомление, я хочу перейти к новому представлению из моего приложения.

Когда приложение находится в Фоновом режиме и нажатие на уведомление ничего не делает с предупреждением обработчика завершения , но когда приложение находится в активном состоянии и запуск уведомления выполняет свою работу, и он переходит к другому представлению. Пожалуйста, вернитесь к этой проблеме. Я прикрепил приведенный ниже код.

ОШИБКА при нажатии на уведомления в фоновом режиме Предупреждение: Делегат UNUserNotificationCenter получил вызов -userNotificationCenter: didReceiveNotificationResponse: withCompletionHandler: но обработчик завершения никогда не вызывался.

Любая помощь приветствуется

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],

                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        // If you are receiving a notification message while your app is in the background,

        let application = UIApplication.shared
        self.window = UIWindow(frame: UIScreen.main.bounds)
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let initialViewController = storyboard.instantiateViewController(withIdentifier: "LaunchScreenViewController")
        self.window?.rootViewController = initialViewController
        self.window?.makeKeyAndVisible()

        if let messageID = userInfo[gcmMessageIDKey] {

            print("Message ID: \(messageID)")

        }

        // Print full message.

        print(userInfo)

        print("Hello u have entered through Push  notification ")

        completionHandler(UIBackgroundFetchResult.newData)
    } 

1 Ответ

1 голос
/ 14 февраля 2020

Здравствуйте, я только что получил решение для моего ответа! Я попытался перейти к другому представлению в методе расширения usernotificationcenter И это сработало.

extension AppDelegate: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        print("Entry through the Notification")

        let application = UIApplication.shared
        self.window = UIWindow(frame: UIScreen.main.bounds)
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let initialViewController = storyboard.instantiateViewController(withIdentifier: "stationListVC")
        self.window?.rootViewController = initialViewController
        self.window?.makeKeyAndVisible()

        if response.actionIdentifier == "remindLater" {
            let newDate = Date(timeInterval: 900, since: Date())
            scheduleNotification(at: newDate)
        }
    }
} 

Спасибо всем за ПОМОЩЬ;)

...