0

I am making an app in Swift that takes a UIWebView and allows the audio to be playing in the background. The problem is, when I click the home button, the audio pauses but you can resume it from control center or the lock screen. How do I make it so it plays through being closed? I have this code in my ApplicationDelegate DidFinishLaunchingWithOptions:

var activeError: NSError? = nil
AVAudioSession.sharedInstance().setActive(true, error: &activeError)

if let actError = activeError {
    println("Error setting audio active: \(actError.code)")
}

var categoryError: NSError? = nil
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: &categoryError)

if let catError = categoryError {
    println("Error setting audio category: \(catError.code
}
lagoon
  • 6,417
  • 6
  • 23
  • 30
  • Have you enabled audio under background modes in capabilities? Also set application does not run in background bool to false in the plist. – Rasputin Aug 10 '15 at 15:04
  • I have enabled both of those. – lagoon Aug 10 '15 at 15:32
  • Check out this answer http://stackoverflow.com/questions/11616001/uiwebview-html5-audio-pauses-in-ios-6-when-app-enters-background I hope it helps. Or also this answer http://stackoverflow.com/questions/8783220/continue-playing-audio-from-html5-player-when-in-ios-background-mode – Rasputin Aug 13 '15 at 14:08
  • None of those worked :( – lagoon Aug 13 '15 at 20:07

0 Answers0