0

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()

}
Community
  • 1
  • 1
James
  • 65
  • 1
  • 8
  • 1
    Did you turn on background modes in the target capabilities? And then set modes audio and air play? Also have you made any changes to the AppDelegate? – MwcsMac Apr 19 '15 at 03:15
  • I added the background mode and set the audio and air play, but it is still not working. What change would I make to AppDelegate? – James Apr 19 '15 at 07:24
  • Take your code above and add it to AppDelegate then in applicationWillResignActive, applicationDidEnterBackground add timerBeep(). – MwcsMac Apr 19 '15 at 20:30

0 Answers0