Play audio from app, even when it is in the background

Solutions Collect From Internet About “Play audio from app, even when it is in the background”

Under capabilities select the following:

enter image description here

In your plist make sure where it says “Application does not run in background” is NO.

enter image description here

Then add the following to your your appDelegate.m file.

  NSError *sessionError = nil;
NSError *activationError = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&sessionError];
[[AVAudioSession sharedInstance] setActive: YES error: &activationError];

In the following method:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}