我正在开发管理BLE设备的应用程序。我正在尝试用didDiscoverCharacteristicsFor方法写数据,如下所示。
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
if let characteristics = service.characteristics {
for characteristic in characteristics {
if characteristic.uuid == CBUUID(string: Common.PinUUID) {
var varInt = 0
let data = Data.init(bytes: &varInt, count: 1);
peripheral.writeValue(data, for: characteristic, type: .withResponse)
}
}
}当我尝试在characteristic上写入数据时,我得到了如下错误。
<CBCharacteristic: 0x283b213e0, UUID = 47E9EE30-47E9-11E4-8939-164230D1DF67, properties = 0x8, value = (null), notifying = NO> - Optional("Writing is not permitted.")我的特点是只写类型。我不知道为什么它会显示这样的错误。
同样,当我尝试读取数据时,我会像下面这样调用。
if characteristic.uuid == CBUUID(string: Common.TemperatureDataUUID) {
print(characteristic)
peripheral.readValue(for: characteristic)
}我得到了如下错误,
<CBCharacteristic: 0x283e77300, UUID = 47E9EE2B-47E9-11E4-8939-164230D1DF67, properties = 0xA, value = (null), notifying = NO> - Optional("Reading is not permitted.")如何解决没有找到任何解决方案的问题?请帮帮忙。
发布于 2019-04-26 17:14:08
显然,在外围设备上设置的权限不允许读写。您的iOS代码可能没有任何错误。
请再次检查外围GATT数据库,以查看其定义是否正确。
https://stackoverflow.com/questions/55861596
复制相似问题