0
votes

I've been searching how to start an audio file after a couple of seconds when the app enters background, and it's working, but there's a small issue I'd love to get rid of.

Without the following code, the AVAudioPlayer won't begin playing:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

But with this code, notification center starts acting like a remote.

I've seen (alarm) apps play a sound after some time, without notification center acting like a remote.

Any suggestions?

You can find the example code here: https://github.com/SabatinoMasala/iPhone-background-audio

1

1 Answers

0
votes

If you are not playing audio when entering in background mode, your app will be suspended.

Maybe adding [[UIApplication sharedApplication] beginReceivingRemoteControlEvents] will prevent your app to be suspended but I am not sure.

Have to tried to create a backgroundTask and play this audio file after a delay?

Also if you want to stay playing in background you have to loop a sound containing silence.