UIBackgroundModes doesn't work s advertise
I red the Apple documentation about UIBackgroundModes and here is what it says :
When this key is present, the system’s audio framework开发者_开发知识库s automatically prevent your application from being suspended when it moves to the background. As long as it is playing audio, the application continues to run in the background to support that audio.
However I have an app that plays an audio stream using the AVPlayer class, and it doesn't work with it. This key is suppose to be there to save us the work of implementing an Audio Session explicitely. Can anyone tell me why this is not working then ? Did anyone used it and made this work ?
Try doing the following before playing your audio:
NSError *sessionError = nil;
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:&sessionError];
Make sure the code for AVPlayer
is actually running. In my case, even though I enabled the key for Core Location
, if I don't actually use in the code by calling start
, the app is suspended, as if no key was defined. For this reason, I usually don't stop
Core Location but simply let it use the least accurate option to preserve device power, yet continue to use background running mode.
精彩评论