12

How does one access the old API for setting audioSession categories? I have an old iPad that I use a video app on that is stuck at iOS 9.3. I'm using Xcode 10. I think it's just method i need here but I'm not sure how to find it.

func configureAudioSession() {
    let audioSession = AVAudioSession.sharedInstance()
    do {
        if #available(iOS 10.0, *) {
            try audioSession.setCategory(.playback, mode: .moviePlayback, options: .allowBluetooth)
        } else {
            // Fallback on earlier versions
        }
    }
    catch {
        print("Setting category to AVAudioSessionCategoryPlayback failed.")
    }
}

Thanks.

aaronium112
  • 2,992
  • 4
  • 35
  • 50

1 Answers1

-3

My solution is as follows:

First I write an OC class with method setAudioCategory, which set the AVAudioSession category to setCategory:AVAudioSessionCategoryPlayback, and then call this method from Swift.

(void) setAudioCategory{
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
}
Acapulco
  • 3,373
  • 8
  • 38
  • 51