2

After the rich push is handled in the background (user clicked on an UNNotificationAction without opening the app - no foreground)), then when you enter the app, there is a duplicate push event resulting in "didReceiveRemoteNotification" execution.

My question is:

Why when I handle the rich push in:

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

and call competionHandler(), same push is being received in:

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

?

Push setup:

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 ?? "")")

                }

Push handler

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()
    }

Push notification payload:

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";

}]

Yair hadad
  • 437
  • 3
  • 17

1 Answers1

1

The "duplicate" push that is being delivered to your app is a silent push notification. Your push notification contains the content-available key in addition to the alert dictionary.

The alert dictionary causes a user-visible notification to be delivered.

The content-available key causes it to be delivered again as a silent push notification, which is not visible to the user.

This is an unsupported configuration. Remove the content-available key and only the user visible push notification will be delivered. If you are actively using silent push send it as a separate push with only the content-available, category and your custom keys.

quellish
  • 21,123
  • 4
  • 76
  • 83
  • If what you say is correct, it supposed to happened to me always, but this is appended only after the client kills the app several times, I always use this configuration and it work until I start to use rice push. can you please add documentation that said it? Thx! – Yair hadad Dec 11 '18 at 06:06