Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

ios - APN custom notification sound issue

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...