iOS 8.1推送通知无声音

Ome*_*jua 15 audio push-notification ios

该设备在iOS 8.1上运行

我正在使用xCode 6.1来编译应用程序.

这是注册推送的代码

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

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

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

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

{
    aps =     {
        alert = "Test Push Message";
    };
}
Run Code Online (Sandbox Code Playgroud)

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

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

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

其他人遇到过这个问题?

rck*_*nes 44

根据Apple的文档,您需要指定default是否要播放默认推送通知:

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

最终的JSON输出:

{
    "aps" :     {
        "alert" : "Test Push Message",
        "sound" : "default"
    };
}
Run Code Online (Sandbox Code Playgroud)


Ole*_*huk 10

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

{
    "aps": {
        "alert": "test",
        "sound": "default"
    }
}
Run Code Online (Sandbox Code Playgroud)