我有两个连接到我的iPad的BluetoothHFP蓝牙设备(bluetoothA2DP和bluetoothLE),我需要检测当前正在获取音频的设备。以下是我用来检测可用蓝牙的代码:

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.portNamedescription.uid区分相同类型的端口。请注意,该名称不保证是唯一的(来自设备)。 UID是系统分配的,不能保证稳定。仅保证它与owningPortUID属性一致,并且在任何给定时间都是唯一的。

目前(iOS 13),UID确实是基于硬件MAC地址的,并且很稳定。格式为aa:bb:cc:dd:ee:ff-tacl(MAC地址后跟-tacl)。长期以来一直如此。至少从iOS 8开始,我就一直在使用这个事实,只要AVAudioSession存在,它就很可能是真的。但这是没有承诺的,而这恰恰是众所周知的,苹果会在不另行通知的情况下进行更改。

关于ios - 如何检测出哪些蓝牙设备音频从中发出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59501241/

10-11 22:31
查看更多