我正在尝试更改远程消息的声音
我已将文件添加到我的项目中,见图1
我还将所有内容添加到我的 AppDelegate 中。在 didFinishLaunchingWithOptions 中我添加了:
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 是:
{"aps":{"alert":"The push message!", "sound":"ice.caf"}}
我不确定我忘记了更改通知声音的哪一步?
当我收到通知时,它总是播放默认声音。
您确定该文件已添加到捆绑包中吗?您可以通过查看来检查这一点Copy Bundle Resources
in Build Phases
.
请参阅此图片以进行说明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)