【问题标题】:Error Domain=CBATTErrorDomain Code=2 "Reading is not permitted." UserInfo={NSLocalizedDescription=Reading is not permitted.}错误域=CBATTErrorDomain 代码=2“不允许读取。” UserInfo={NSLocalizedDescription=不允许读取。}
【发布时间】:2019-04-26 05:58:56
【问题描述】:

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

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

【问题讨论】:

  • 我之前在将 MI 手环 3 与 iOS 设备连接时遇到了同样的问题。通过在访问数据之前将身份验证设置为蓝牙设备来解决问题。我会尽快分享示例代码
  • 您好,当我将数据从一台连接的设备发送到另一台设备时,我也遇到了问题。 func peripheral(_ peripheral: CBPeripheral, didWriteValueFor features: CBCharacteristic, error: Error?) { 我收到错误域=CBATTErrorDomain Code=3“不允许写入。” UserInfo={NSLocalizedDescription=不允许写入。某些设备工作正常,数据已发送,但其他设备未收到任何响应以及通知。如何在其他设备中读取相同的数据。@Vikas @ COVID19

标签: ios swift bluetooth-lowenergy core-bluetooth


【解决方案1】:

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

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

【讨论】:

  • 也就是说,我必须检查设备数据库??
  • 是的,请检查外围设备上的代码,因为那是实际发送错误代码的设备。
  • Error Domain=CBATTErrorDomain Code=2 "不允许读取。" UserInfo={NSLocalizedDescription=不允许读取。}
  • 外设设置不正确。它设置了读取属性位,但没有设置读取权限。请检查该设备的固件。您的 iOS 代码可能没有任何问题。
  • 那么在这种情况下,一定是通信流中发生了一些事情,后来使外围设备拒绝了“不允许读取”的请求。您应该首先检查外围设备为什么会发送该错误代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-29
  • 1970-01-01
  • 2020-05-20
  • 2021-12-20
  • 1970-01-01
相关资源
最近更新 更多