自定义声音远程推送通知iOS无法正常工作 [英] Custom sound remote push notification iOS not working
问题描述
我正在尝试更改远程消息的声音
I'm trying to change the sound of the remote message
我已将文件添加到我的项目中,见图1
I've added the file into my project, see picture 1
我还将所有内容添加到我的AppDelegate中.在didFinishLaunchingWithOptions中,我添加了:
I've also added everything into my AppDelegate. In the didFinishLaunchingWithOptions I've added:
if (UIDevice.currentDevice().systemVersion as NSString).floatValue >= 8.0 {
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Sound | .Alert | .Badge, categories: nil))
UIApplication.sharedApplication().registerForRemoteNotifications()
} else {
UIApplication.sharedApplication().registerForRemoteNotificationTypes(.Badge | .Sound | .Alert)
}
//Clear badge
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
UIApplication.sharedApplication().cancelAllLocalNotifications()
我实现的其他方法是:
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let deviceTokenString = deviceToken.hexString
println(deviceTokenString)
let task = service.writeForNotifications(token: deviceTokenString, completionHandler: {
})
task.resume()
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
println("Failed to get token: \(error)")
}
我从服务中收到的Json是:
The Json I received from the service is:
{"aps":{"alert":"The push message!", "sound":"ice.caf"}}
我不确定是否忘记更改通知声音? 当我收到通知时,它将始终播放默认声音.
I'm not sure whitch step I've forgotten to change the sound of the notification? When I receive a notification it always plays the default sound.
推荐答案
您确定文件已添加到分发包中吗?您可以通过查看Build Phases
中的Copy Bundle Resources
进行检查.
Are you sure the file is added to the bundle? You can check this by looking at the Copy Bundle Resources
in Build Phases
.
查看此图片以进行澄清:
See this image for clarification:
这篇关于自定义声音远程推送通知iOS无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!