繁体   English   中英

iOS推送通知没有声音

[英]iOS Push Notification No Sound

这是注册推送的代码

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [application registerForRemoteNotifications];
}
else
{
    [application registerForRemoteNotificationTypes: (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}

它可以在应用程序向服务器注册时正常工作。

PEM文件也正确完成,因为我可以使用沙盒APNS将推送发送到我的设备。

当我从didReceiveRemoteNotification打印我的JSON有效负载时,我得到:

{
    aps =     {
        alert = "Test Push Message";
    };
}

问题是当我收到推送时(即使设备设置为响亮)它也不会发出声音。

据我所知,如果你没有在JSON有效载荷中指定声音,它应该播放默认的OS声音。

在手机上的应用程序通知设置中,默认情况下启用声音,因为当我注册时,我指定了UIUserNotificationTypeSound

其他人遇到过这个问题?

根据Apple的文档 ,如果要播放默认推送通知,则需要指定default值:

应用程序包中声音文件的名称。 此文件中的声音将作为警报播放。 如果声音文件不存在或默认值被指定为值,则播放默认警报声音。 音频必须采用与系统声音兼容的音频数据格式之一; 请参阅准备自定义警报声音以获取详细信

最终的JSON输出:

{
    "aps" :     {
        "alert" : "Test Push Message",
        "sound" : "default"
    };
}

您应该将服务器JSON输出修改为此。 default它是手机通知的声音类型。

{
    "aps": {
        "alert": "test",
        "sound": "default"
    }
}

当我们的应用程序收到推送通知时播放声音,您的json必须包含声音属性。 所以json喜欢这个

{
    "aps":{
    "alert" :"your test message",
    "sound":"default"
        };
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM