Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created January 30, 2018 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitomad/fb620741c336b6d87fa89a4468a88a6e to your computer and use it in GitHub Desktop.
Save fitomad/fb620741c336b6d87fa89a4468a88a6e to your computer and use it in GitHub Desktop.
Enable iOS app to play sound in background
//
// MARK: - Step 1. Configuration
//
/*
You need to enable one feature in order to allow our app play sounds in *background* mode.
Select the Capabilities tab of project's main target, go to Background Modes section and select:
**Audio, AirPlay and Picture in Picture
*/
//
// MARK: - Step 2. Code
//
// Copy code below at point when you start your audio system or similar.
do
{
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
}
catch
{
print("err @ \(#function) -> No se puede establecer la categoría de sonido.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment