gpt4 book ai didi

ios - 错误域=CBATTErrorDomain 代码=2 "Reading is not permitted."UserInfo={NSLocalizedDescription=不允许读取。}

转载 作者:行者123 更新时间:2023-11-28 07:28:02 25 4
gpt4 key购买 nike

我正在开发管理 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)
}
}
}

当我尝试在特性上写入数据时,出现如下错误。

<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.")

如何解决它没有找到任何解决方案?请帮忙。

最佳答案

很明显,在外设端设置的权限不允许读写。您的 iOS 代码可能没有任何问题。

请再次检查外设GATT db是否定义正确。

关于ios - 错误域=CBATTErrorDomain 代码=2 "Reading is not permitted."UserInfo={NSLocalizedDescription=不允许读取。},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55861596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com