更新时间:2023-02-01 20:34:57
我建议您查看 Sameer对于Swift 2.0的回答,几个月前.与Swift 2.0完美配合.
I would suggest checking out Sameer's answer to this for Swift 2.0, just a few months back. Works perfectly with Swift 2.0.
let sess = AVAudioSession.sharedInstance()
if sess.otherAudioPlaying {
_ = try? sess.setCategory(AVAudioSessionCategoryAmbient, withOptions: []) //
_ = try? sess.setActive(true, withOptions: [])
}