I'm trying to change the sound of the remote message
I've added the file into my project, see picture 1
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()
The other methods I've implemented are:
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)")
}
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With