我使用以下代码检测可用输出,但它并没有拿起我连接的蓝牙设备。我知道我的蓝牙设备已正确连接,因为我正在播放音乐。
let session = AVAudioSession.sharedInstance()
for description in session.currentRoute.outputs {
if description.portType == AVAudioSessionPortHeadphones {
NSLog("headphone plugged in")
let alertActin = UIAlertAction(title: "Headphones", style: UIAlertActionStyle.default, handler:nil)
alertActin.setValue(UIColor.blue, forKey: "titleTextColor")
alert.addAction(alertActin)
} else if description.portType == AVAudioSessionPortBluetoothA2DP {
NSLog("Bluetooth plugged in")
let alertActin = UIAlertAction(title: description.portName, style: UIAlertActionStyle.default, handler:nil)
alertActin.setValue(UIColor.blue, forKey: "titleTextColor")
alert.addAction(alertActin)
} else if description.portType == AVAudioSessionPortBluetoothLE {
NSLog("Bluetooth plugged in")
let alertActin = UIAlertAction(title: description.portName, style: UIAlertActionStyle.default, handler:nil)
alertActin.setValue(UIColor.blue, forKey: "titleTextColor")
alert.addAction(alertActin)
}
else {
NSLog("")
}
}