Audio playing while app in background iOS Audio playing while app in background iOS objective-c objective-c

Audio playing while app in background iOS


Apple has a nice Technical Q&A article about this in its documentation (see also Playing and Recording Background Audio).

I think one big thing missing is that you haven't activated the Audio Background Mode in the Xcode settings:enter image description here

Maybe also adding [self.player prepareToPlay] in your alert method is helpful.


I have an App than also needs background audio but my App works with the App background mode "Voice over IP" as it needs to record sometimes. I play background audio telling the App singleton I need to play audio in background:

UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;if([thePlayer play]){    newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];   }

EDIT: You must call [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL]; before your app goes to background. In my app, it is at the same time you start playing, in yours, if the player might be started in background, you should do:

- (void)applicationDidEnterBackground:(UIApplication *)application{  // You should retain newTaskId to check for background tasks and finish them   newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];   }


Apple docs

Either enable audio support from the Background modes section of the Capabilities tab

Or enable this support by including the UIBackgroundModes key with the audio value in your app’s Info.plist file