iOS 8.1推送通知无声音

前端之家收集整理的这篇文章主要介绍了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有效负载中指定声音,它应该播放默认的操作系统声音.

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

有人遇到这个问题吗?

解决方法

根据 Apple’s documentation,如果要播放默认推送通知,则需要指定默认值:

The name of a sound file in the app bundle. The sound in this file is
played as an alert. If the sound file doesn’t exist or default is
specified as the value,the default alert sound is played. The audio
must be in one of the audio data formats that are compatible with
system sounds; see Preparing Custom Alert Sounds for details.

最后的JSON输出

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

猜你在找的iOS相关文章