play audio in background on intervals iOS

101 Views Asked by At

So I am working on an app that requires different audio files to be played using an NSTimer every X amount of time. Yes, it needs to play the audio in the background as well, but I have had inconsistent results trying to do so. I have searched the web thoroughly to find a solution to this problem, but I have had no luck.

I have enabled background modes and checked off item 0(audio) and made sure it was in my info.plist. I have set the "App does not run in background" key to NO in the info.plist. In the viewDidLoad method of the VC, I have set the AVAudioCategory to categoryPlayback and set the AVAudioSession to active. I have also moved these lines of code around in different places of the app to look for different results, and the best results I have gotten is that the app will continue to run in the background sometimes and at other times it will suspend.

Through all of my searching, I have seen forums explaining how to play audio in the background. However, I have not found any solutions to playing short audio files in the background intermittently on different scheduled intervals.

I know of at least one app in the App Store that is able to do this, and they use the ducking feature of AVFoundation to duck audio playing in the background(Im not sure if other frameworks are able to duck background audio, such as AudioToolbox, but I would like to have ducking enabled for my app).

If anyone knows of any legal solution for my problem, your assistance would be greatly appreciated.

0

There are 0 best solutions below