我使用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规格,但没有运气
任何建议都会很好!