0

I want do code an alarm-clock. Now the alar-clock should play a music-file at a specific time. But I don't know how to call the method with AVAudioPlayer while the app is in background? Can you please help me I want do this for the first time.

thanks :)

user3195648
  • 67
  • 1
  • 1
  • 6

1 Answers1

0

You should not use a long-running background thread in order to trigger a sound at a certain time. A running thread prevents the device from going to sleep, greatly increasing power requirements.

Further, Apple greatly restricts the amount of processing you are allowed to do from the background. You can request time to complete a long task from the background, but only a short period of time is allowed. (A few minutes at most if memory serves.

You should probably create a local notification instead. The local notification will display a banner message on the lock screen if your app is not running, and optionally play a sound that you specify.

Take a look at the UILocalNotification Class Reference in Xcode for more information.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • Thanks but I want not only a alarm, I want for example a timer that stops music automatically when you go to sleep, so you say that the music should stop in 20 minutes and you lock the device or put the app in background and after 20 minutes it stops the music. – user3195648 Jun 12 '14 at 15:19