smorhaim
smorhaim

Reputation: 798

How to play a sound while running in the background?

I need to be able to play a sound while running the application in the background.

I tried with UILocalNotifications but the file needs to be part of the bundle, and that will not be the case, as I need to generate the sound files on the fly...

So is there any way that I can play a sound while running in the background?

Thanks.

Upvotes: 2

Views: 758

Answers (1)

russbishop
russbishop

Reputation: 17219

You can't, unless you continuously play audio and have the appropriate audio session category set for your app... then your app doesn't go to sleep, it continues to run (again so long as audio is playing).

This is part of the design limitations of iOS multitasking.

Apple has allowed people to get away with having a continuously looping blank audio file (AVAudioPlayer loop = -1 with a 1-sec blank CAF file) if the app is primarily audio related and it is obvious to the user that this has battery life implications (and can be disabled by the user), but YMMV... you app can also be rejected for this.

Upvotes: 2

Related Questions