IOS Custom Sound Remote Push Notification Not Working

I am trying to change the sound of a deleted message

I added the file to my project, see figure 1

Structure application

I also added everything to my AppDelegate. In didFinishLaunchingWithOptions, I 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()

Other methods implemented by me:

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)")
}

Received from Json service I:

{"aps":{"alert":"The push message!", "sound":"ice.caf"}}

I'm not sure I decided to forget to change the notification sound? When I receive a notification, it always plays the default sound.

+4
source share
3 answers

Are you sure the file has been added to the kit? You can check it out by looking Copy Bundle Resourcesat Build Phases.

See this image for more details:

enter image description here

+9
source

"" "". , , .

, , .

0

,

  • 30
  • ( .aiff,.wav .caf), , , , ,
  • , .
  • The payload (push json data) should be in the recording format (in your case, it looks good)
  • The push notification should be Capabilitiesin the project settings of Capabilitiesof you (in your case, it seems to be on because you get a notification with default sound)
0
source

Source: https://habr.com/ru/post/1588960/


All Articles