【发布时间】:2015-05-20 09:44:53
【问题描述】:
我正在尝试更改远程消息的声音
我已将文件添加到我的项目中,见图 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"}}
我不确定我忘记更改通知的声音是哪一步? 当我收到通知时,它总是播放默认声音。
【问题讨论】:
-
请检查“ice.caf”是否确实在生成的“ipa”文件中。它可能已添加到项目中,但未添加到您的构建中。或者格式无效。例如,尝试使用“wav”文件。
-
是的,这是我的问题!非常感谢!
-
是的,IOS 8.3 或最新版本有问题,它可以在 IOS 7 上运行。这可能是一个错误。
-
@cyberlobe 您必须通过推送通知传递它。当您正确设置推送通知时,iOS 会自动处理它。查看我从服务中收到的 json。
-
@HannesVandenBerghe 完成了,实际上问题出在 PHP 脚本中。仍然添加了默认声音。我将其更改为自定义声音名称并且有效
标签: ios swift apple-push-notifications