【发布时间】: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