2

在后台处理完富推送后(用户在未打开应用的情况下点击了 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";

}]

4

1 回答 1

1

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

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

content-available密钥导致它作为静默推送通知再次传递,用户不可见。

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

于 2018-08-21T16:57:25.230 回答