13

I am currently working on an app and I have implement firebase Push Notification service into my app. I am recieving notification on my iphone but I am unable to set the custom alert sound that I want.

  • I added the sound as a .caf
  • I added the sound to the Copy Bundle Resources

using print (userInfo) I have collected this data that is incomming from Firebase

aps: {
alert =     {
    body = MSG;
    title = Title;
};
sound = default;}, {...}, sound: alarm.caf

I understand where the problem is, I just dont understand how to fix it so that the app plays my custom notification sound.

Firebase notification console IMG

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Mentos
  • 483
  • 1
  • 4
  • 14
  • u got answer for ur question. if yes update it in answer zone. other could get benefitted – ChenSmile Aug 30 '16 at 08:47
  • I enable sound (you have it disbaled in your image) and set the key "sound" to my custom sound's filename, however the userInfo["aps"]["sound"] is still just "default" – vikzilla Mar 01 '17 at 20:47
  • 1
    i am getting notifications from fcm . now , i want to make functionality such as when i will get notification from fcm , app should play a sound file without even touching notification message . do you know how to do that ? didRecieveRemoteNotification will only get executed when user tap on notification . but i want to play a sound file like alarm tune . please guide me through it . – Moxarth Jul 06 '17 at 10:17

3 Answers3

6

Problem with Firebase is that you can not send sound parameter like custom parameter with Firebase Console, if you try this as you do, you will get this parameter in app outside of aps Dictionary and the system will not recognize it as a sound to be played although the sound file is into the project.

The only solution for this problem is you have some API/server through which you'll be sent a Firebase notification. When server send you a notification with sound param it will be within aps Dictionary and application will play this sound when the notification arrives.

Noblak
  • 71
  • 1
  • 6
  • 1
    Not sure why your and @Mentos replies have been downvoted; you have accurately described the issue that I am also facing with Firebase Console messaging. – vikzilla Mar 01 '17 at 21:23
  • i am getting notifications from fcm . now , i want to make functionality such as when i will get notification from fcm , app should play a sound file without even touching notification message . do you know how to do that ? didRecieveRemoteNotification will only get executed when user tap on notification . but i want to play a sound file like alarm tune . please guide me through it . – Moxarth Jul 06 '17 at 10:16
  • @Moxarth have you got any solutions for your problem? – Midhun Narayan Nov 06 '18 at 04:27
1

After much research I have not found any solution. Under Firebase Messaging Docs, and

Table 2a. iOS — keys for notification messages

it is indicated that Firebase does allow for the Sound key to be included in the payload but as seen in the code printed by didRecieveRemoteNotification,

aps: {
alert =     {
    body = MSG;
    title = Title;
};
sound = default;}, {...}, sound: alarm.caf

Firebase doesn't include the Sound key inside the aps hence not calling the sound key by the app.

The workaround that I used for my app is Easy APNs Provider which is a handy and easy app to use for development purposes, a major issue is that it doesn't have the ability to register and remove notifications automatically.

lastly: for Push Notifications to my published apps, I have opted for a dedicated server which I run off of my website

Mentos
  • 483
  • 1
  • 4
  • 14
  • 1
    i am getting notifications from fcm . now , i want to make functionality such as when i will get notification from fcm , app should play a sound file without even touching notification message . do you know how to do that ? didRecieveRemoteNotification will only get executed when user tap on notification . but i want to play a sound file like alarm tune . please guide me through it . – Moxarth Jul 06 '17 at 10:15
1

It's been over 5 years, but if someone still looking for an answer, here is what I did.

  1. Make sure you have configured Firebase Messaging & receiving Notifications.

  2. Add .caf ( sound file ) to the app. It must be visible on 'Target' - > 'Build Phases' & then under 'Copy Bundle Resources'

enter image description here

  1. Delete the app from the device ( This is important )

  2. I use Postman as my server, so message format would be,

    { 
     "notification": {
     "title": "Hello",
     "sound":"small_message.caf",
     "body": "You have a new Job"
    },
    
    "to": "your device token"
    }
    
Heshan Sandeepa
  • 3,388
  • 2
  • 35
  • 45