我有这段代码可以将值写入蓝牙设备的特性:
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类型。
可能是什么原因?
答案 0 :(得分:-1)
刚 只有一个可以工作 这取决于你的characterstic.properties属性
宣言 SWIFT
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;