Changing UIBackgroundModes of audio at runtime

I have an application that plays music and I want to enable background modes. My audio category is set to kAudioSessionCategory_MediaPlayback, and if I add an audio line to my UIBackgroundModes inside my info.plist file, it keeps playing audio. So far so good.

Now I want to provide this option to my users to choose whether the audio plays in the background or not. I tried to get the file and delete the key, but nothing happens so far. I did (in a UIButton driven selector):

    -(void) disableBackgroundAudio:(UIButton*)button{
        NSDictionary *plistDict = [[NSBundle mainBundle] infoDictionary];
        [plistDict setValue:@"" forKey:@"UIBackgroundModes"];
    }

      

If I print this value in the console, before and after, I see that there was "audio" before it, and after that I get an empty string. However, if I then press the home button, the sound always plays regardless of whether I mute the sound.

I guess this is probably not the way to update (although I'm not sure if it's even possible) the info.plist file. Is it even possible? In the end, I think giving users a choice is better for my particular application, and I've seen other applications do it.

Any help would be greatly appreciated.

+3


source to share


3 answers


Info.plist

is part of your application package. All files in this package are immutable.



Keep the value audio

and just pause the music playing when the app enters the background (in case the user has disabled this setting).

+3


source


Why do you need to decide? If the user doesn't want to hear background audio, just mute the music when the app goes into the background ... Anyway, you probably shouldn't change the app bar at runtime.



0


source


Can't you just mute the sound when your app enters the background if the user doesn't want to run in the background? Also, if you want your application to terminate completely, if it occurs when the user doesn't want to run in the background, call the exit (...) function.

But in answer to your question, no, you cannot change background modes (or anything in the info.plist file) at runtime.

0


source







All Articles