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

audio, background, xcode

Solution

Under capabilities select the following:

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

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;
}

Problem

I am having difficulties determining how I would play audio in the background for my iOS app. I have a NSTimer and wish to have a sound be played when it reaches 5 minutes, even when in the background. I already have the audio background mode enabled, but unsure how to accomplish my idea.

Original source