Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS中查找未连接蓝牙的音频设备列表_Ios_Swift_Bluetooth - Fatal编程技术网

如何在iOS中查找未连接蓝牙的音频设备列表

如何在iOS中查找未连接蓝牙的音频设备列表,ios,swift,bluetooth,Ios,Swift,Bluetooth,我正在尝试列出所有蓝牙连接的音频设备。但是没有登录委托函数。还尝试了来自 下面是我的代码 import UIKit import CoreBluetooth import AVFoundation class ViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralManagerDelegate { override func viewDidLoad() { super.viewDidLoad()

我正在尝试列出所有蓝牙连接的音频设备。但是没有登录委托函数。还尝试了来自

下面是我的代码

import UIKit
import CoreBluetooth
import AVFoundation

class ViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralManagerDelegate {

override func viewDidLoad() {
    super.viewDidLoad()

    do{
        try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: AVAudioSessionCategoryOptions.AllowBluetooth)
    } catch{
        print(error)
    }

    let manager = CBCentralManager.init(delegate: self, queue: nil)
    manager.scanForPeripheralsWithServices(nil, options: nil)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

func centralManagerDidUpdateState(central: CBCentralManager) {
    print(central.state)
}

func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) {
    print(peripheral)
}

func peripheralManagerDidUpdateState(peripheral: CBPeripheralManager) {
    print(peripheral)
}

}

在我的例子中,有一个音频播放器和一个按钮(就像音乐中默认的airplay按钮)。单击按钮时,它应显示所有已连接的蓝牙设备。是否可以列出所有设备?此外,我不能使用苹果的MKVolumeView,因为我必须进一步创建cordova插件。

目前有Objective-C解决方案。希望您能轻松转换。这里还有一个:音频不适合蓝牙低能量,而CoreBooth仅适用于蓝牙低能量。请使用
AVAudioSession
@tech4242-Thanx查看回复。虽然我的问题还没有解决。我已经尝试了你给出的链接中给出的解决方案。另外,我已经将我的问题编辑得更具体一些。@Larme Thanx回答。虽然我的问题还没有解决。此外,我还对我的问题进行了编辑,使之更加具体。