FCM custom sound not working on iOS when in background mode

Viewed 4645

Did something change with FCM recently? Our apps use custom sound in push notifications. This has been working fine on both Android and iOS, whether in foreground, background, or closed. But recently something seems to have changed as the same PHP code we've been using suddenly stopped working for custom sounds when the app is closed or in background mode? (The notification is delivered, but it just uses the default device sound).

I was able to get it working again on Android by just including the sound files in /app/src/res/raw (we used to keep them there, but for a long time now it wasn't needed yet always worked... apparently it's needed again). Ok Android solved.

But for iOS it still has stopped working! I'm not sure if it's something I'm doing wrong in xCode or if I need to change the PHP code used to trigger the notifications. So here's both to review:

I am using:

  • xCode 11.6
  • iOS target 11.0
  • Testing on real device, iOS 13.6.1
  • Sound files are at {Project Name}/Resources/ and were added with "Copy items if needed" and "Create groups" both checked

Server side code to trigger notifications (which always worked fine before and has not been changed):

{
  "notification": {
      "title": "Test Title",
      "body": "Test Body",
      "sound": "sound_file.mp3",
  },
  "registration_ids": ["APA...g","fl...CS"]
}

Please help... thought I was past all of this years ago...ugggg!

6 Answers

We created a ticket with Google/Firebase support. Their answer: There's no ongoing issue on our end that may cause the custom sound to not work. However, by specifying a custom sound, the sound file must be on the user's device already, either in the app's bundle or in the library/Sounds folder of the app's container. You can refer to this documentation for more information. For FCM, there isn't any extra sound processing, only passing the payload field, so as long as the payload on the client shows "sound" file is successfully passed down, there may be an issue with the setup. If there's no recent change for your application and the sound files, then this may be something caused on Apple's end. With that, it's best to check this with them.

We discovered that we apparently use the legacy HTTP API so we tested the newer HTTP v1 version. (described here: https://firebase.google.com/docs/cloud-messaging/migrate-v1 ) This solved the problem for us. Custom sound is back.

In the mean time Firebase support replied the following and now acknowledges there is a problem with the legacy HTTP API.

Thanks for sharing your observations, Mark.

We’ve received similar reports regarding this issue and that indicates that this is not an unusual issue in relation to the increasing reports on the Stack Overflow discussion that you’ve mentioned too. With that, this issue was just recently identified as a bug with our Legacy API that’s not properly handling the custom sound for iOS. Our engineering team has identified the fix for this issue, and we couldn’t provide a definite timeline at the moment for the release in our production. I’ll let you know once I have an update for this issue.

For now, you might consider using our HTTP v1 API to send your messages. Apologies for the inconvenience this may have caused you.

We just touched base with the Firebase dev team and they were able to reproduce the issue. They have just created an internal ticket to fix this. Will follow up here on the resolution progress

After several additional rounds communication with Firebase, here is the current status update and their response:

I would like to let you know that this issue was just recently identified as a bug with our Legacy API that’s not properly handling the custom sound for iOS. Our FCM gurus have identified the fix for this issue, and the fix is about to be released on our production, but we can’t share any exact details or timeline for the release. The fix should let you send notifications properly based on your custom sounds configuration and there should be no code changes needed on your end. Also, it should still properly handle the notification sounds if the app is closed or in background state for your iOS application.

We are furthermore told that for the moment, migration from FCM HTTP to HTTP v1 is the only work around. Will post here again once we hear confirmation on the fix to the Legacy API (which most people reading this as using). Stay tuned...

On my side, no matter what sound name I set, I always receive on ios side "sound": "default"

Sending:

{
  "notification": {
      "title": "Alert",
      "body": "Test Message",
      "sound": "alert.aiff",
  },
  "registration_ids": ["APA...g","fl...CS"]
}

Receiving:

{
    aps =     {
        alert =         {
            body = "Test Message";
            title = Alert;
        };
        "content-available" = 1;
        sound = default;
    };
}

The only reason for this to happen is that FCM set sound to default while it redirect to APNS. Need ask google

Please check guys, Google has fixed this issue !!

Related