brk
brk

Reputation: 121

Amazon SNS with Firebase iOS Cloud Messaging Notifications not working

I am testing push notifications with with FCM and SNS. (SNS -> FCM (ios/android). Android works without issue. I can trigger notifications from SNS to FCM to my android device.

I then tested connected the iOS version to firebase and added certificates, etc. and can trigger push notifications from within firebase test page to the iOS device without issue.

The issue is I can’t trigger notifications from AWS SNS to FCM with the iOS version (android version works no problem). I would expect it to work the same way as android. Are there any custom parameters that need to be added to the payload for the iOS version to work that are different from android when triggering a notification from SNS?

This is the custom payload i'm sending from SNS to FCM to test with:

{ "GCM": "{ "data": { "message": "Sample message for Android endpoints" }, "content_available": true, "mutable_content": true} , "notification": {"body": "Enter your message", "sound": "default"}" }

Upvotes: 1

Views: 3772

Answers (2)

Tiago Alexandre
Tiago Alexandre

Reputation: 101

I've tested on the Amazon SNS console and after many attempts, I figured out how to format the JSON for sending notifications to iOS devices. If you want to send silent notifications with the same Android's pattern, you have to use a format like this:

{ "GCM": "{ \"notification\" : {\"content_available\" : true }, \"data\": { \"body\": \"Sample message for iOS endpoints\", \"title\":\"Hello world\"} }" }

If you want to send a sound notification, you can use this:

{ "GCM": "{ \"notification\": { \"body\": \"Sample message for iOS endpoints\", \"title\":\"Hello world\"} }" }

Upvotes: 10

brk
brk

Reputation: 121

I found the solution:

The default format SNS sends when you publish messages to FCM works for android but not iOS. I had to send a custom payload to FCM in the format shown below and it worked! I would expect the payload being sent to FCM to work across both iOS/android but it does not.

{ "GCM": "{"notification": { "body": "Sample message for Android endpoints", "title":"Hello world" } }" }

Good references:

https://stackoverflow.com/a/61166165/1123434

https://stackoverflow.com/a/38626398/1123434

Upvotes: 4

Related Questions