APN custom notification sound issue

2019-01-20 10:46发布

问题:

I have remote notifications setup and working fine. I however have to play a custom sound when a notification is received (when app is NOT in foreground). I have added a file called customSound.wav to my app bundle and made sure "add to targets" is selected when i drag and drop it into my project (is this the correct way?). Server-side: the same file name has been specified as "sound": "customSound.wav". In my didReceiveRemoteNotification i am printing the userInfo dictionary and it is coming up like this:

aps =     
{
    alert = "Good Evening Sir";
    badge = 1;
    "custom_filed1" = 1;
    "custom_field2" = "AAA-BBB-CCC";
    name = "Sir Hubert";
    sound = default;
};

As you can see, sound is still "default". I am aware of the fact that if the sound specified can not be found, the default sound is played- will the sound value in the dictionary also be "default" or it should be the file name that was specified in payload json. Is the order in which these are specified in the payload important. I have tried suggestions from other threads but not working for me. I can not show the json as I do not have access to the system at the moment. Any suggestions as to what I may be doing wrong ?

回答1:

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