【问题标题】:Can't discover bluetooth mouse and keyboard through CoreBluetooth (macos Swift)无法通过 CoreBluetooth (macos Swift) 发现蓝牙鼠标和键盘
【发布时间】:2018-11-09 01:05:30
【问题描述】:

我对使用 CoreBluetooth 框架的设备有疑问。基本上我需要在 OSX 中复制标准蓝牙发现应用程序的功能,所以我做了以下操作:

let bluetoothManager = CBCentralManager()

//Lifecycle

 override func viewDidLoad() {
    super.viewDidLoad()
    bluetoothManager.delegate = self
}

//delegate method

func centralManagerDidUpdateState(_ central: CBCentralManager) {
    switch central.state {
    case .poweredOn:
        print("powered on")
        central.scanForPeripherals(withServices: nil, options: nil)
    case .unknown:
        print("state unknown")
    case .resetting:
        print("resetting")
    case .unsupported:
        print("unsupported")
    case .unauthorized:
        print("unauthorized")
    case .poweredOff:
        print("powered off")
    }
}

此代码仅发现 iphone 和电视,但忽略了苹果的键盘和鼠标。有什么我想念的吗?也许我需要在 withServices 中定义一些服务:?

现在我只是将外围设备打印到控制台中:

func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
    print("discovered some perilherials", peripheral)    
}

我搜索了 bluetooth.com 规格,但没有运气

任何建议都会很好!

【问题讨论】:

    标签: swift macos bluetooth core-bluetooth


    【解决方案1】:

    核心蓝牙只能发现 BLE GATT 配置文件设备。对于旧设备和配置文件(例如键盘宣传的 HID 配置文件),您需要使用 IOBluetooth framework

    【讨论】:

      猜你喜欢
      • 2015-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-14
      • 2019-07-26
      • 1970-01-01
      • 2011-05-12
      相关资源
      最近更新 更多