Describe the question
From iOS 10 there is support for replacing remote notifications on the device using apns-collapse-id. https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns?language=objc
Digging in SNS documentation I found support for CollapseId flag in Amazon Pinpoint. I couldn't make it work with Amazon SNS. Is there a way to make it work with sns / is there planned support for it in the future?
Hey @dominiczaq, you're right, looking at the documentation here, I wasn't able to find the support for Collapsed flag for SNS service, I can mark this as a feature request for the service team and discuss with them.
That would be cool, considering that both iOS and android support natively push notifications collapsing. Without apns-collapse-id / CollapseId one must use Notification Service Extensions. Which is sad, as this could be done much simpler with flag mentioned above.
Thank you for your time to review it. 馃檱
@dominiczaq: Could you provide more details about how to use Notification Service Extensions to work around the lack of apns-collapse-id ? Are you able to change the request.identifier in the extension or otherwise able to cancel/collapse one of two notifications?
Hey @jnross, cancelling previous notifications is possible and quite simple. I've used steps provided in this article - https://medium.com/the-guardian-mobile-innovation-lab/how-to-replace-the-content-of-an-ios-notification-2d8d93766446. It works fine. One thing to note is to add some timeout after calling UNUserNotificationCenter.current().removeDeliveredNotifications(identifiers) and after calling contentHandler. removeDeliveredNotifications is asynchronous and does not provide any callback so if you call contentHandler immediately without any timeout, the message to cancel will not be removed from notification center. In my case 100ms did the trick.
It's not as smooth as directly using apns-collapse-id but I don't think there are other options right now.
This is already supported using the reserved message attribute AWS.SNS.MOBILE.APNS.COLLAPSE_ID documented here: https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html#sns-attrib-mobile-reserved
I tested it using the JavaScript SDK and was able to get replace previously delivered notification with the same apns-collapse-id.
This is already supported using the reserved message attribute
AWS.SNS.MOBILE.APNS.COLLAPSE_IDdocumented here: https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html#sns-attrib-mobile-reservedI tested it using the JavaScript SDK and was able to get replace previously delivered notification with the same
apns-collapse-id.
Closing this now, please reach out if you have any questions, I can reopen if there are still questions.
Most helpful comment
Hey @jnross, cancelling previous notifications is possible and quite simple. I've used steps provided in this article - https://medium.com/the-guardian-mobile-innovation-lab/how-to-replace-the-content-of-an-ios-notification-2d8d93766446. It works fine. One thing to note is to add some timeout after calling
UNUserNotificationCenter.current().removeDeliveredNotifications(identifiers)and after callingcontentHandler.removeDeliveredNotificationsis asynchronous and does not provide any callback so if you callcontentHandlerimmediately without any timeout, the message to cancel will not be removed from notification center. In my case 100ms did the trick.It's not as smooth as directly using
apns-collapse-idbut I don't think there are other options right now.