Xcode 10 报错 'setCategory' is unavailable in Swift
do {
try session.setCategory(AVAudioSession.Category.playAndRecord)
} catch let err{
print("设置类型失败:\(err.localizedDescription)")
}
解决方法
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.")
}
}