xcode APN自定义通知声音问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13341919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
APN custom notification sound issue
提问by pnizzle
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:
我有远程通知设置并且工作正常。但是,当收到通知时(当应用程序不在前台时),我必须播放自定义声音。我在我的应用程序包中添加了一个名为 customSound.wav 的文件,并确保在我将它拖放到我的项目中时选择了“添加到目标”(这是正确的方法吗?)。服务器端:相同的文件名已被指定为 "sound": "customSound.wav"。在我的 didReceiveRemoteNotification 中,我正在打印 userInfo 字典,它是这样出现的:
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 ?
如您所见,声音仍然是“默认”。我知道如果找不到指定的声音,则播放默认声音 - 字典中的声音值是否也为“默认”或应该是有效负载 json 中指定的文件名。这些在有效载荷中指定的顺序是否重要。我尝试了其他线程的建议,但对我不起作用。我无法显示 json,因为我目前无法访问系统。关于我可能做错了什么的任何建议?
回答by spider1983
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"; }; }
例如:{ 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
我正在使用它并在我的通知中获得成功的自定义警报; 保持声音持续时间尽可能小。我使用了这种文件格式: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
如果你想测试通知,那么你可以试试这个应用程序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
我没有对这个应用做任何标记,但它有利于测试推送通知