AVAudioSession未检测到连接的蓝牙设备

我正在使用下面的代码来检测可用的输出,但它没有检测到我连接的蓝牙设备。我知道我的蓝牙设备是正确连接的,因为我正在用它播放音乐。

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

转载请注明出处:http://www.dlaisen.com/article/20230526/1725858.html