ios - Garmin 可穿戴设备和 iOS 设备之间的 BLE 通信
问题描述
我想创建一个 Garmin 可穿戴应用程序(数据字段),它将使用蓝牙 LE(Garmin 上的 BluetoothLowEnergy API 和 iOS 上的 CoreBluetooth)与我的 iOS 应用程序通信。Garmin 的 API 有一个限制 - 它只能作为中央设备工作,因此我将 iPhone 配置为“虚拟”外围设备(我使用自己的调试应用程序和 LightBlue 对其进行了测试)。
我设法在我的 Garmin Vivoactive 3 Music 和我的 iPhone 之间建立了连接,但我仍然有一些问题要让它工作。
从 Garmin 可穿戴设备中,我设法搜索、查找和配对设备(我的 iPhone 虚拟外围设备),以便两者:self.pairedDevice = BluetoothLowEnergy.pairDevice(scanResult)
并且BluetoothLowEnergy.getPairedDevices().next()
不返回空值。
我遇到的问题是在 Garmin 设备上从未调用过此回调:
function onConnectedStateChanged(device, connectionState) {
if (connectionState==BluetoothLowEnergy.CONNECTION_STATE_CONNECTED) {
displayString = "Connected";
}
if (connectionState==BluetoothLowEnergy.CONNECTION_STATE_DISCONNECTED) {
displayString = "Disconnected";
}
}
此外,当发现我的虚拟外围设备时,我可以在广告数据中看到可用的服务,但是一旦设备配对,调用就会device.getServices()
返回一个空的迭代器。
我已经检查过BluetoothLowEnergy.getAvailableConnectionCount()
是3,所以连接数限制应该没有问题。有没有办法强制连接?
在 iOS 我做这样的事情:
let service = CBMutableService(type: serviceCbuuid, primary: true)
let writeableCharacteristic = CBMutableCharacteristic(type: characteristicCbuuid,
properties: [.write],
value: nil,
permissions: [.writeable])
service.characteristics = [writeableCharacteristic]
currentService = service
peripheralManager = CBPeripheralManager(delegate: self,
queue: DispatchQueue.global(qos: .userInteractive))
然后我添加currentService
usingperipheralManager?.add(currentService)
并在didAdd service
回调中通过调用peripheral.startAdvertising(options)
.
也许我错过了 iOS 端的一些设置来完成这项工作?
解决方案
推荐阅读
- php - PHP SQL Server连接工作或不工作
- reactjs - 改进对 React 的错误处理 | 还原 | MERN 应用程序
- html - XSLT:如何避免在 HTML 的属性中添加自闭合标签
- c - 从函数返回多个错误之一并在 C 中结束程序的最佳实践是什么?
- ios - 等到应用内购买完成,直到执行操作
- css - 从底部绝对定位不创建溢出滚动条
- ssl - wso2 apim 1.10.0 SSL 通信
- typescript - 打字稿声明:模块检测和命名空间
- javascript - 更改从文本文件读取的 js 文件的样式
- redux - Redux saga:redux-saga 工作原理的内部结构