富推送在后台处理后(用户在未打开应用的情况下点击了UNNotificationAction - 无前台)),然后当您进入应用时,会出现重复推送事件导致“didReceiveRemoteNotification”执行。
我的问题是:
为什么当我处理富人插入时:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
并调用competitionHandler(),收到相同的推送:
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-available
、category
和您的自定义键。
关于IOS - 通过单击 UNNotificationAction 处理后的丰富推送重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51929483/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |