Xcode 10 报错 'setCategory' is unavailable in Swift

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.")
    }
}

参考

  • 如何为iOS 9设置audioSession类别?

你可能感兴趣的:(Xcode 10 报错 'setCategory' is unavailable in Swift)