Ios 如何检测蓝牙设备的音频输出
我有两个BluetoothHFP蓝牙设备连接到我的iPad(bluetoothA2DP和bluetoothLE),我需要检测哪个设备当前正在接收音频。下面是我用来检测蓝牙可用性的代码:Ios 如何检测蓝牙设备的音频输出,ios,swift,bluetooth,avaudiosession,Ios,Swift,Bluetooth,Avaudiosession,我有两个BluetoothHFP蓝牙设备连接到我的iPad(bluetoothA2DP和bluetoothLE),我需要检测哪个设备当前正在接收音频。下面是我用来检测蓝牙可用性的代码: let currentRoute = audioSession.currentRoute for description in currentRoute.outputs { if convertFromAVAudioSessionPort(description.
let currentRoute = audioSession.currentRoute
for description in currentRoute.outputs {
if convertFromAVAudioSessionPort(description.portType) == convertFromAVAudioSessionPort(AVAudioSession.Port.bluetoothA2DP) {
//Do Something
break
}else if convertFromAVAudioSessionPort(description.portType) == convertFromAVAudioSessionPort(AVAudioSession.Port.bluetoothHFP) {
//Do Something
break
}else if convertFromAVAudioSessionPort(description.portType) == convertFromAVAudioSessionPort(AVAudioSession.Port.bluetoothLE){
//Do Something
break
}
}
我可以使用什么来查找BluetoothHFP设备中的哪一个当前正在获取音频?您可以使用
description.portName
和description.uid
来区分相同类型的端口。请注意,名称不保证唯一(它来自设备)。UID是系统分配的,不保证稳定。它只承诺与owningPortUID
属性一致,并且在任何给定时间都是唯一的
目前(iOS 13)的UID基于硬件MAC地址,并且是稳定的,这是正确的。它的格式是aa:bb:cc:dd:ee:ff tacl
(MAC地址后跟-tacl
)。这是事实已经很长一段时间了。至少从iOS 8开始,我就一直在使用这一事实,而且很有可能,只要AVAudioSession存在,这一事实就是正确的。但这并不是承诺,这正是众所周知的苹果会在未经通知的情况下改变的事情