Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Austin-Michael Komatz
7,684 PointsHow do I use a system sound as the sound for a UILocalNotification? (Swift)
Hi, I need help urgently. I have a UILocalNotification, and I want to be able to play a system sound as the UILocalNotification.soundName, which is of type string. How do I use a system sound as the notification sound?
I have searched extensively online and I cannot find anything that fully satisfies the question, so please, if anyone knows how to do this show me. Thank you so much!
// create a new alarm/notification
let alarm: UILocalNotification = UILocalNotification()
alarm.category = "wakeUpAlarms"
alarm.alertAction = "turn off the alarm"
alarm.alertBody = "Time to wake up!"
alarm.fireDate = NSDate(timeIntervalSinceNow: Double(secondsUntilFire))
// This is where I get the sound
let systemSoundID: SystemSoundID = 1016
// And I want to apply that sound to the alarm, but it doesn't work
alarm.soundName = systemSoundID
// schedule the alarm
UIApplication.sharedApplication().scheduleLocalNotification(alarm)