iOS蓝牙特性写入无响应

标签 ios bluetooth-lowenergy

我有这段代码可以为蓝牙设备的特性写入值:

CBPeripheral *speaker = ...;
NSData *data = ...;
CBCharacteristic *chara = ...;
[speaker writeValue:data forCharacteristic:chara type:CBCharacteristicWriteWithResponse];

数据值为:

(lldb) po data
<02080101 a800e001>

chara 具有以下属性:

CBCharacteristicPropertyRead
CBCharacteristicPropertyWriteWithoutResponse
CBCharacteristicPropertyWrite
CBCharacteristicPropertyAuthenticatedSignedWrites

当使用 CBCharacteristicWriteWithResponse 类型时,此代码工作正常,并且扬声器显示新值,但不适用于 CBCharacteristicWriteWithoutResponse 类型。

这可能是什么原因?

最佳答案

只是 只有一个可以工作 这取决于你的 characterstic.properties 属性

声明 快捷方式

struct CBCharacteristicProperties : RawOptionSetType {
    init(_ rawValue: Int)
    init(rawValue rawValue: Int)
    static var Broadcast: CBCharacteristicProperties { get }
    static var Read: CBCharacteristicProperties { get }
    static var WriteWithoutResponse: CBCharacteristicProperties { get }
    static var Write: CBCharacteristicProperties { get }
    static var Notify: CBCharacteristicProperties { get }
    static var Indicate: CBCharacteristicProperties { get }
    static var AuthenticatedSignedWrites: CBCharacteristicProperties { get }
    static var ExtendedProperties: CBCharacteristicProperties { get }
    static var NotifyEncryptionRequired: CBCharacteristicProperties { get }
    static var IndicateEncryptionRequired: CBCharacteristicProperties { get }
}
OBJECTIVE-C
typedef enum {
   CBCharacteristicPropertyBroadcast = 0x01,
   CBCharacteristicPropertyRead = 0x02,
   CBCharacteristicPropertyWriteWithoutResponse = 0x04,
   CBCharacteristicPropertyWrite = 0x08,
   CBCharacteristicPropertyNotify = 0x10,
   CBCharacteristicPropertyIndicate = 0x20,
   CBCharacteristicPropertyAuthenticatedSignedWrites = 0x40,
   CBCharacteristicPropertyExtendedProperties = 0x80,
   CBCharacteristicPropertyNotifyEncryptionRequired = 0x100,
   CBCharacteristicPropertyIndicateEncryptionRequired = 0x200,
} CBCharacteristicProperties;

关于iOS蓝牙特性写入无响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30309263/

相关文章:

ios - UISegmentedControl 自定义在 ios 7 中不起作用

android - 联系信标 : Inconsistent and unreliable results when determining beacon distance

bluetooth - 使用 BLE 芯片将设备连接到智能手机

ios - BLE writeValue 到外设

ios - 为什么我的 UISearchBar 在点击时会缩小?

ios - 创建 firebase 数据结构时遇到问题

ios - 对象未使用的属性有任何危害吗?

ios - Swift 的 map 和 filter 函数时间复杂度

ios - 如何在iOS中获取配对BLE设备?

ios - 此平台不支持 CoreBluetooth BLE 硬件