Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FCM custom sound not working on iOS when in background mode

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!

like image 270
Mike Darling Avatar asked Aug 14 '20 22:08

Mike Darling


People also ask

How do you get custom notification sounds on iOS?

Set Custom Notification Sounds On iPhone To set a custom notification sound go to 'Settings,' scroll down, and then tap on 'Sound & Haptics. ' Under 'Sounds and Vibration Patterns,' select the type of notification that needs to be changed. From the menu, choose the sound that needs to be set as the notification sound.

Does FCM work on iOS?

Stay organized with collections Save and categorize content based on your preferences. For Apple client apps, you can receive notification and data payloads up to 4000 bytes over the Firebase Cloud Messaging APNs interface.

Why is my iPhone not making any notification sounds?

Open the iPhone Settings and tap on Sounds & Haptics. There, tap on Text Tone and check if the Alert Type is set to None. If yes, select any of the tones listed as your notification sound.


1 Answers

Detail information:

https://medium.com/@ThatJenPerson/authenticating-firebase-cloud-messaging-http-v1-api-requests-e9af3e0827b8

Sample code:

{
"message":{
  "token":"ewrTK.....",
  "notification":{
     "title":"Breaking News",
     "body":"New news story available."
  },
  "data":{
     "title":"Notification title",
     "body":"Notfication body"
  },
  "apns":{
     "payload":{
        "aps":{
           "sound":"notification.mp3"
        }
     }
  }
}
}
like image 90
Fatih Hayrioğlu Avatar answered Sep 25 '22 02:09

Fatih Hayrioğlu