I have a Countdown Timer app that counts down but does not beep and crashes when it hits 0 if the phone is locked or on a different app.
I found this 3 year old link for Objective C objective c play music in the background
but the only thing I could figure was to add "Application does not run in background to Info.plist and set it to "No"
Here is my function to play it:
func timerBeep() {
// preperation
AVAudioSession.sharedInstance().setCategory("AVAudioSessionCategoryPlayback", error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)
// play sound
var error: NSError?
audioPlayer = AVAudioPlayer(contentsOfURL: sound, error: &error)
audioPlayer.prepareToPlay()
audioPlayer.play()
}