gpt4 book ai didi

iOS 推送通知 - didReceiveRemoteNotification :fetchCompletionHandler: never called in foreground

转载 作者:行者123 更新时间:2023-11-29 00:14:44 25 4
gpt4 key购买 nike

我已经在我的应用程序中实现了远程通知,但是我遇到了 didReceiveRemoteNotification:fetchCompletionHandler: 的问题。

当手机屏幕锁定时,我会收到通知。如果用户滑动通知,应用会返回前台并调用 didReceiveRemoteNotification:fetchCompletionHandler:

但是,如果应用程序在前台运行,则永远不会调用 didReceiveRemoteNotification:fetchCompletionHandler:。可能是什么原因?

我正在使用 iOS 10.3.2

最佳答案

您正在使用哪个 iOS 版本?

There are different methods for iOS 9 and iOS 10.

以下是适用于 iOS 10 的

    //Called when a notification is delivered to a foreground app.
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

}


//Called to let your app know which action was selected by the user for a given notification.
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

}

对于 iOS 9,请确保在 didBecomeActive 中注册您的通知

UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
UIApplication.shared.registerForRemoteNotifications()

并在您的didReceiveRemoteNotification

func application(_ application: UIApplication, didReceiveRemoteNotification data: [AnyHashable : Any]) {

if application.applicationState == .active {
//foreground state
}

}

最好的方法是在 didReceiveRemoteNotification 中放置一个调试器并进一步检查。

关于iOS 推送通知 - didReceiveRemoteNotification :fetchCompletionHandler: never called in foreground,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45567178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com