Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Configure Audio Session for background audio mode (iOS Project)
import UIKit
import AVFoundation
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// enable playback category: this is required for background audio to function normally
let audioSession = AVAudioSession.sharedInstance()
try? audioSession.setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault)
try? audioSession.setActive(true, with: [])
return true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment