0

I have a requirement to aggregate remote notifications of the same type.

example: if a user received a push notification saying:"user 1 commented on your post", and then received "user 2 commented on your post", when receiving the second push I should remove the first notification and create a custom notification saying "2 users have commented on your post".


I'm getting the counter in the userInfo dictionary and I'm using NotificationService Extension in order to modify the notification's content.

the problem is I'm presenting 2 notifications:

  1. "user 1 commented on your post"
  2. "user 3 and 2 others have commented on your post"

instead of only the 2nd notification.

I've tried initializing UNNotificationRequest with custom identifier but still I'm getting double notifications (the original one and then the custom one).

    UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: ["push.comment"])
    if let username = bestAttemptContent.userInfo["sender"] as? String,
       let count = bestAttemptContent.userInfo["views_counter"] as? Int {
            bestAttemptContent.title = "\(username) and \(count) others  have commented on your post"
    }
    bestAttemptContent.body = "tap to see"
    let request = UNNotificationRequest(identifier: "push.comment", content: bestAttemptContent, trigger: nil)
    UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

I tried using available-content : 1 in the notification's payload, but I'm not able to modify the notification when the app is terminated (not in background/foreground).

Basically I want a similar behaviour to facebook's messenger app.

Any Suggestions?

Beygel
  • 113
  • 13
  • it should be `mutable-content: 1` – JustinM Feb 27 '18 at 21:50
  • @JustinM yes I know that in order to invoke notification service extension I need to set `mutable-content: 1`, the problem is that the notification appears twice just like I said (first is the original, second is the modified) – Beygel Feb 28 '18 at 08:02

2 Answers2

0

Push Notifications grouping is a feature that is provided in Android applications, but it is impossible to achieve the same on iOS. Because it should be handled by operation system(in other case it will be not possible to achieve when app is closed or minimized) and iOS doesn't provide this support.

Taras Chernyshenko
  • 2,729
  • 14
  • 27
  • I don't agree, you can see facebook's implementation. you can receive multiple messages on your iOS device and as soon as you open up your messages on your computer all the notifications from your phone gets cleared so I know it's possible. btw, you can group notifications by using `Thread-Identifier` payload parameter although its not my desire. – Beygel Feb 28 '18 at 08:02
0

So I read in Apple's documentation that when setting content-available : 1 in the aps object it launches the app in a background mode and its possible to handle the received silent push. its important to avoid setting the mutable-content : 1 and add background modes with remote notifications on in the apps configurations.

Beygel
  • 113
  • 13