iOS推送通知没有声音

时间:2014-11-17 13:07:13

标签: ios audio push-notification

这是注册推送

的代码
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

其他人遇到过这个问题?

3 个答案:

答案 0 :(得分:44)

根据Apple's documentation,如果您要播放默认推送通知,则需要指定default

  

应用包中声音文件的名称。这个文件中的声音是   作为警报播放。如果声音文件不存在或默认为   指定为值,播放默认警报声音。音频   必须是与其兼容的音频数据格式之一   系统声音;有关详细信息,请参阅准备自定义警报声音。

最终的JSON输出:

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

答案 1 :(得分:10)

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

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

答案 2 :(得分:3)

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

Acrobat.MenuItemExecute('Copy');
相关问题