自定义声音不播放推送通知
Custom Sound not playing for Push Notifications
使用 Backendless 推送通知,我的设备成功接收了它们。但是当我尝试将消息的 "ios-sound" 参数设置为我添加到项目中的 mp3 时,它不播放任何声音:
the Backendless docs 中表示设置 "ios-sound" 执行以下操作:
Sets either a URL for the sound notification to play on the device or
an array of bytes for the sound to play.
我不知道我做错了什么。嗯...
如果您在您的设备上成功收到通知,
那么您的音频文件可能很大
自定义声音播放时长必须在 30 秒以内。如果自定义声音超过该限制,则会播放默认系统声音。因此请确保您的自定义声音少于 30 秒。
您的音频数据必须是 aiff、wav 或 caf 文件。
服务器上的文件名和您在捆绑包中的文件名应该相同。并将您的 mp3 转换为给定格式之一,然后当应用程序处于非活动状态时仅播放声音。
除了我已经在执行的 registerForRemoteNotifications() 之外,还通过调用 registerUserNotificationSettings 解决了问题。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
backendless.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)
//NEEDED TO DO THE FOLLOWING TWO LINES
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.sharedApplication().registerForRemoteNotifications()
return true
}
我之前没有调用它的原因是 Backendless Docs 说只需调用 .registerForRemoteNotifications() 即可涵盖警报、徽章和声音。然而这似乎是不正确的。
使用 Backendless 推送通知,我的设备成功接收了它们。但是当我尝试将消息的 "ios-sound" 参数设置为我添加到项目中的 mp3 时,它不播放任何声音:
the Backendless docs 中表示设置 "ios-sound" 执行以下操作:
Sets either a URL for the sound notification to play on the device or an array of bytes for the sound to play.
我不知道我做错了什么。嗯...
如果您在您的设备上成功收到通知, 那么您的音频文件可能很大
自定义声音播放时长必须在 30 秒以内。如果自定义声音超过该限制,则会播放默认系统声音。因此请确保您的自定义声音少于 30 秒。
您的音频数据必须是 aiff、wav 或 caf 文件。
服务器上的文件名和您在捆绑包中的文件名应该相同。并将您的 mp3 转换为给定格式之一,然后当应用程序处于非活动状态时仅播放声音。
除了我已经在执行的 registerForRemoteNotifications() 之外,还通过调用 registerUserNotificationSettings 解决了问题。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
backendless.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)
//NEEDED TO DO THE FOLLOWING TWO LINES
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.sharedApplication().registerForRemoteNotifications()
return true
}
我之前没有调用它的原因是 Backendless Docs 说只需调用 .registerForRemoteNotifications() 即可涵盖警报、徽章和声音。然而这似乎是不正确的。