您好,我正在使用 Apple Sample BLTE 应用程序来显示配对对话框。(iPhone 到 iPhone)
这是我用于创建特征的代码
self.transferCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID]
properties: CBCharacteristicPropertyRead| CBCharacteristicPropertyNotifyEncryptionRequired
value:nil
permissions:CBAttributePermissionsReadable];
以上代码摘自Apple的一篇文章link
这是我通知并尝试读取特征时的代码
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID]]) {
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
[peripheral readValueForCharacteristic:characteristic];
}
我的问题是,当我尝试此代码时,我没有收到配对对话框,而是在 didUpdateValueForCharacteristic
中收到此错误
2017-04-24 17:24:58.636 BTLE Transfer[1351:457263] Error discovering characteristics: Authentication is insufficient.
这基本上意味着我需要配对才能阅读,但框架不显示配对对话框。
我在这里做错了什么?请帮忙。
编辑: 我更新了我的特征如下:
self.transferCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID]
properties: CBCharacteristicPropertyRead| CBCharacteristicPropertyNotifyEncryptionRequired
value:nil
permissions:CBAttributePermissionsReadEncryptionRequired];
最佳答案
配对对话框未显示的真正问题是因为我在两部 iPhone 上都有相同的 iCloud 帐户。当我从一台设备上删除帐户时出现配对对话框。
这个答案帮助我弄明白了 link
关于ios - 无法使用 CoreBluetooth 显示配对对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43587679/