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 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...