1

I am successfully modifying my remote notification payload using the UINotificationServiceExtension.

I want to change the alert sound based on the user's choice here. In order to do that I need to assign a UINotificationSound object to the bestAttemptContent:

bestAttemptContent.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "alertTone.caf"))

This will work for tones which I have created and imported into my project. One named alertTone.caf in the above example.

However, I want to use the system alert tones instead of my own. I know I can set the default tone but I want access to other custom tones. Is there anyway at all to do this?

alionthego
  • 8,508
  • 9
  • 52
  • 125

1 Answers1

0

You can't reference the system sounds for UNNotificationSound, but you can try to play the sound when you receive the notification in the service extension.

// import
import AVFoundation

// create a sound ID, in this case its the tweet sound.
let systemSoundID: SystemSoundID = 1016

// Play the correct sound when the notification is received in the service extension
AudioServicesPlaySystemSound (systemSoundID)

Source for playing system sounds here.

This is a list of all the system sound ids that you can use for reference.

dsringari
  • 104
  • 2