UIBackgroundModes does not work.

I am stealing Apple's documentation about UIBackgroundModes, and here is what it says:

When this key is present, audio systems automatically prevent your application from pausing when it moves to the background. As it plays audio, the application continues to run in the background to support this audio.

However, I have an application that plays an audio stream using the AVPlayer class, and it does not work with it. This key, presumably, should be there to save us the work of implementing the audio session explicitly. Can someone tell me why this is not working? Has anyone used it and done this job?

+4
source share
2 answers

Try the following before playing the sound:

NSError *sessionError = nil; AVAudioSession *session = [AVAudioSession sharedInstance]; [session setCategory:AVAudioSessionCategoryPlayback error:&sessionError]; 
+4
source

Make sure the AVPlayer code is actually running. In my case, even if I turned on the key for Core Location , if I really do not use the code by calling start , the application pauses as if no key was defined. For this reason, I usually donโ€™t stop Core Location, but just let it use the least accurate option to save the deviceโ€™s power, but I continue to use the background mode.

0
source

Source: https://habr.com/ru/post/1340547/


All Articles