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"
    };
}

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...