使用 CoreBluetooth 为 Mi Band 3 制作配对(身份验证)弹出窗口
Make Pairing(Authentication) popup for Mi Band 3 using CoreBluetooth
我想从Mi Band 3读取心率、睡眠数据,为此我需要验证或为此进行配对弹出。
以下是配对详情:
let BLE_Pairing_Service_CBUUID = CBUUID(string: "0xFEE1")
let Pairing_Chars_UUID = CBUUID(string: "00000009-0000-3512-2118-0009AF100700")
我正在使用以上详细信息来阅读特征。但我不知道 生成验证弹出窗口 。请大家帮忙。
所以经过很多努力我找到了解决方案:
步骤:1- 用于身份验证向身份验证特征发送 18 个字节。
步骤:2- 创建 18 大小的数组,即 18 个字节,将其 转换为 Data()
类型。
步骤:3- 现在将 18 字节数据写入您的外围设备。
if characteristic.uuid == Pairing_UUID {
let cmdBytes: [UInt8] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]
let cmd = Data(cmdBytes)
peripheral.writeValue(cmd, for: characteristic, type: .withoutResponse)
peripheral.setNotifyValue(true, for: characteristic)
}
在didDiscoverCharacteristicsFor
方法中写上上面的代码。
我想从Mi Band 3读取心率、睡眠数据,为此我需要验证或为此进行配对弹出。 以下是配对详情:
let BLE_Pairing_Service_CBUUID = CBUUID(string: "0xFEE1")
let Pairing_Chars_UUID = CBUUID(string: "00000009-0000-3512-2118-0009AF100700")
我正在使用以上详细信息来阅读特征。但我不知道 生成验证弹出窗口 。请大家帮忙。
所以经过很多努力我找到了解决方案:
步骤:1- 用于身份验证向身份验证特征发送 18 个字节。
步骤:2- 创建 18 大小的数组,即 18 个字节,将其 转换为 Data()
类型。
步骤:3- 现在将 18 字节数据写入您的外围设备。
if characteristic.uuid == Pairing_UUID {
let cmdBytes: [UInt8] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]
let cmd = Data(cmdBytes)
peripheral.writeValue(cmd, for: characteristic, type: .withoutResponse)
peripheral.setNotifyValue(true, for: characteristic)
}
在didDiscoverCharacteristicsFor
方法中写上上面的代码。