iOS推送通知无声音 [英] iOS Push Notification No Sound

查看:1100
本文介绍了iOS推送通知无声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是注册推送的代码

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

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

It works fine as the app registers with the server.

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

The PEM files are also done correctly as I can send a push to my device using sandbox APNS.

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

When I print my JSON payload from didReceiveRemoteNotification I get this:

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

问题是,当我收到推送消息时(即使设备设置为大声),它也没有播放声音.

The issue is when I receive my push (even when the device is set to loud) it doesn't play a sound.

据我所知,如果您未在JSON有效负载中指定声音,则它将播放默认的OS声音.

From my knowledge, if you don't specify a sound in the JSON payload it should play the default OS sound.

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

In my App notification settings on the phone the sound is enabled by default because when I register I specify UIUserNotificationTypeSound.

还有其他人遇到这个问题吗?

Anyone else come across this issue?

推荐答案

根据

According to Apple's documentation you need to specify default if you want to the default push notification to be played:

应用程序捆绑包中声音文件的名称.该文件中的声音是 起到警示作用.如果声音文件不存在或默认为 指定为值时,将播放默认警报声音.音讯 必须采用与以下设备兼容的音频数据格式之一 系统声音;有关详细信息,请参见准备自定义警报声音.

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推送通知无声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆