Tuesday, September 4, 2018

How can I set APNS notification identifiers for remote push notifications created using AWS SNS?

Leave a Comment

I'm using the AWS SNS SDK in the backend to dispatch remote notifications to my app, and I need to be able to set the notification identifier so that certain notifications replace previously delivered copies by default as described in the iOS developer docs:

If you use the same identifier when scheduling a new notification, the system removes the previously scheduled notification with that identifier and replaces it with the new one.

This is easy to do with local notifications, because they're scheduled in the app where you can set the notification identifier when scheduling the notification.

However, with remote notifications, I can't seem to find any way to set the notification identifier using the SNS SDK (in a Lambda written in .NET).

According to the API reference, SNS returns a response with a message ID (which is likely the notification identifier), but I can't see any way to set the identifier myself.

Does anyone know how to do so? Or does SNS simply not allow this?

1 Answers

Answers 1

You can customize payload, as described by AWS: https://docs.aws.amazon.com/sns/latest/dg/mobile-push-send-custommessage.html

When sending platform-specific payloads in messages using the Amazon SNS console, the data must be key-value pair strings and formatted as JSON with quotation marks escaped. The following example, including formatting and spaces for readability, shows a sample custom message for the GCM platform with key-value pair within the message body and formatted as JSON.

{ "GCM":"{ "data":{ "message":"Check out these awesome deals!", "url":"www.amazon.com" } }" }

You could add your id as a custom field.

EDIT: In case you need to add headers, you may want to proxy the request through a Lambda function: https://docs.aws.amazon.com/sns/latest/dg/sns-lambda.html And this is a thread here showing how to add response headers using Lambda: Setting http response header from AWS lambda

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment