iOS 8.1推送通知没有声音

该设备在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)]; } 

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

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

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

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

问题是,当我收到我的推(即使设备设置为大声),它不会发出声音。

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

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

任何人遇到这个问题?

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

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

最终的JSON输出:

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

你应该修改服务器的JSON输出到这个。 default它是您的手机上的通知的声音types。

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

为了播放声音,当我们的应用程序收到推送通知您的JSON必须包含声音属性。 所以json是这样的

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