Search code examples
iosfirebasefirebase-cloud-messagingamazon-sns

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


Solution

  • 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