didReceiveRemoteNotification在单击通知(背景)时不起作用,但在应用程序为前景时起作用

问题描述 投票:0回答:1

需要有关PUSH通知的一些解决方案。我从堆栈中尝试了不同的解决方案,但无法为我工作!

我的问题是,当我从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)
    } 
ios swift push-notification appdelegate
1个回答
0
投票

didFinishLaunchingWithOptions中致电:

fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

    }
© www.soinside.com 2019 - 2024. All rights reserved.