Skip to content

Instantly share code, notes, and snippets.

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 hashaam/3f5968a54184fef4cc556f3aa7221baa to your computer and use it in GitHub Desktop.
Save hashaam/3f5968a54184fef4cc556f3aa7221baa to your computer and use it in GitHub Desktop.
Configure Audio Session for background audio mode (iOS Project)
// https://hashaam.com/2017/06/15/configure-audio-session-for-background-audio-mode-ios-project/
import UIKit
import AVFoundation
@UIApplicationMain
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