gpt4 book ai didi

IOS - 通过单击 UNNotificationAction 处理后丰富的推送重复

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:01:57 28 4
gpt4 key购买 nike

在后台处理丰富的推送后(用户在没有打开应用程序的情况下单击了 UNNotificationAction - 没有前台)),然后当您进入应用程序时,会出现重复的推送事件,导致“didReceiveRemoteNotification”执行。

我的问题是:

为什么当我处理丰富的推送时:

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

并调用 competionHandler(),在以下位置接收到相同的推送:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)

?

推送设置:

UNUserNotificationCenter.current().delegate = self

UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
if granted {
print("UNUserNotificationCenter auth granted")
Utils.performTaskOnMain {
application.registerForRemoteNotifications()
}
} else {
print("UNUserNotificationCenter auth error = \(error?.localizedDescription ?? "")")

}

推送处理程序

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
{
print("AppDelegate didReceiveRemoteNotification, with info:\(userInfo)")
handleNotificationUserInfo(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}


@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
UserNotificationsManager.shared.handleActionIdentifierForReceivedNotification(response)
completionHandler()
}

推送通知负载:

info:[AnyHashable("content-available"): 1, AnyHashable("messageInfo"): {"push_type":"XXXX","category":"videoCategory","mediaUrl":"https://XXXX.png","threadId":"24274","alertTitle":null,"initiator":"XXXXX XXXX.mp3","alertBody":null,"mutableContent":true}, AnyHashable("media-url"): https://XXXXX.png, AnyHashable("aps"): {
alert = {
body = "XXXXX";
};
badge = 56;
category = "XXX.videoCategory";
"content-available" = 1;
"mutable-content" = 1;
sound = "XXXX.mp3";

}]

最佳答案

传递到您的应用程序的“重复”推送是静默推送通知。除了 alert 字典之外,您的推送通知还包含 content-available 键。

alert 字典会导致传递用户可见的通知。

content-available 键导致它作为静默推送通知再次传送,这对用户是不可见的。

这是一个不受支持的配置。删除 content-available 键,将只发送用户可见的推送通知。如果您正在积极使用静默推送,请将其作为单独的推送发送,仅包含 content-availablecategory 和您的自定义 key 。

关于IOS - 通过单击 UNNotificationAction 处理后丰富的推送重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51929483/

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