Created
January 15, 2018 23:37
-
-
Save dmennis/fe1132fa2bae3d620b8f4d87d8b7f3f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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