Skip to content

Instantly share code, notes, and snippets.

@dmennis
Created January 15, 2018 23:37
Show Gist options
  • Save dmennis/fe1132fa2bae3d620b8f4d87d8b7f3f0 to your computer and use it in GitHub Desktop.
Save dmennis/fe1132fa2bae3d620b8f4d87d8b7f3f0 to your computer and use it in GitHub Desktop.
func pushNotificationHandler(userInfo: Dictionary<AnyHashable,Any>) {
// Parse the aps payload
let apsPayload = userInfo["aps"] as! [String: AnyObject]
// Play custom push notification sound (if exists) by parsing out the "sound" key and playing the audio file specified
// For example, if the incoming payload is: { "sound":"tarzanwut.aiff" } the app will look for the tarzanwut.aiff file in the app bundle and play it
if let mySoundFile : String = apsPayload["sound"] as? String {
playSound(fileName: mySoundFile)
}
}
// Play the specified audio file with extension
func playSound(fileName: String) {
var sound: SystemSoundID = 0
if let soundURL = Bundle.main.url(forAuxiliaryExecutable: fileName) {
AudioServicesCreateSystemSoundID(soundURL as CFURL, &sound)
AudioServicesPlaySystemSound(sound)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment