Apn Custom Notification Sound Issue

APN custom notification sound issue

No your sound key should have the sound file name you want to play.

{
aps =
{
alert = "message";
sound = "sound file name.extension";
badge = 1;
};
}

eg:
{
aps =
{
alert = "message";
sound = "tone.caf";
};
}

I am using this and getting successful custom alert on my notification;
keep sound duration as small as possible. I did with this file format: aiff, caf

if u want to test notification then u can try this app https://itunes.apple.com/us/app/easy-apns-provider-push-notification/id989622350?mt=12

I am not doing any marking of this app but it is good for testing push notification

Custom sound remote push notification iOS not working

Are you sure the file is added to the bundle? You can check this by looking at the Copy Bundle Resources in Build Phases.

See this image for clarification:

Sample Image

Unable to play sound when APNS push notification comes in

Try changing the value of sound to "sound": "default".
If that doesn't work, try moving the sound from the "alert" to "aps"

Custom sound push notification does not work (Flutter)

Reading this it seems that it should be manage automatically (if you didn't use a notification builder) on Android but you have to specify the .mp3 extension too and put it inside notification field and not data one..

"sound": "alarm.mp3"

iOS behaves very differently under the hood but you can use a custom sound by setting the sound: field in the notification payload too. Anyway .mp3 is not a valid APN notification file format, and you need to specify also the file extention.

"sound": "filename.caf"

Follow Apple documentation in order to forge your custom sound file for your app.

mp3 is not a valid format

Preparing Custom Alert Sounds

Local and remote notifications can specify custom alert sounds to be
played when the notification is delivered. You can package the audio
data in an aiff, wav, or caf file. Because they are played by the
system-sound facility, custom sounds must be in one of the following
audio data formats:

  • Linear PCM

  • MA4 (IMA/ADPCM)

  • µLaw

  • aLaw

Place custom sound files in your app bundle or in the
Library/Sounds folder of your app’s container directory. Custom
sounds must be under 30 seconds when played. If a custom sound is
over that limit, the default system sound is played instead.

You can use the afconvert tool to convert sounds. For example, to
convert the 16-bit linear PCM system sound Submarine.aiff to IMA4
audio in a CAF file, use the following command in the Terminal app:

afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d ima4 -f caff -v

For exampole to convert your mp3 file in a caf file you could type in terminal:

afconvert -f caff -d LEI16 alarm.mp3 alarm.caf

Read this doc in order to have a deep inside of all generic and specific notifciation payload fields.

UPDATE

I've tested the Android part and I can confirm that putting your .mp3 file in res/raw/ folder the sound is played as documented and expected.

That's my notification payload:

{
"to" : "my_device_token",
"collapse_key" : "type_a",
"priority" : "high",
"notification" : {
"body" : "Test Notification body for custom sound {{datestamp}}",
"title": "Custom sound alert.mp3",
"sound": "alert.mp3"
}
}

Sample Image

I've tested also the iOS version after converting .mp3 file to .caf file in that way:

afconvert -f caff -d LEI16 alert.mp3 alert.caf

the same json payload with the different filename works:

{
"to" : "my_device_token",
"collapse_key" : "type_a",
"priority" : "high",
"notification" : {
"body" : "Test Notification body for custom sound {{datestamp}}",
"title": "Custom sound alert.mp3",
"sound": "alert.caf"
}
}

Remember to add the file in your main bundle.

Sample Image

That works if the app is terminated or in background.

If you want to show an alert and play a sound when the app is in foreground you have to manage it on onMessage event like someone already have told you here, or you can use a platform-channel here to build your own notification with a Notification.Builder on Android and a UNNotificationCenter on iOS (for example).

UPDATE

This issue has been solved. See here the official comment:

Hey all /p>

As part of our roadmap (#2582) we've just shipped a complete rework of
the firebase_messaging plugin that aims to solve this and many other
issues.

If you can, please try out the dev release (see the migration guide
for upgrading and for changes) and if you have any feedback then join
in the discussion here.

Given the scope of the rework I'm going to go ahead and close this
issue in favor of trying out the latest plugin.

Thanks everyone /p>

FCM custom sound not working on iOS when in background mode

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...

APNS notification sound for iOS

If you want to play a sound other than the default one, you will need to package the sound in your bundle and specify the file name of the sound in the payload. For example, if I were to include a sound file called notificationCupcake.caf in my app, I would include this JSON key/value pair in the push:

 "sound": "notificationCupcake.caf"

iOS Unable to play custom sound for remote notifications

For Default sound:

According to the apple documentation & guidelines to play default sound you must have to send "Default" value in sound file. Other wise it will not play default sound either.

For custom sound:

You need to pass custom sound file name in place of default inside your php script**.

  1. For custom sound file must be exist in your Xcode project in
    resources.
  2. Make sure sound file duration no longer than 30 seconds. Otherwise
    it will play default sound.
  3. And you must add the below key UILocalNotificationDefaultSoundName
    inside .plist file. See below image:

Sample Image



Related Topics



Leave a reply



Submit