gpt4 book ai didi

iphone - 核心蓝牙内部的可写特性

转载 作者:行者123 更新时间:2023-11-29 11:00:39 27 4
gpt4 key购买 nike

我正在使用核心蓝牙。我添加了写/读特性的功能。在此之前,我想检查该特性是否可写。为此,我使用了 characteristic.properties 我的代码是:

    if (characteristic.properties==CBCharacteristicPropertyRead)
{
[peripheralDevice readValueForCharacteristic:characteristic];
}
else if(characteristic.properties==CBCharacteristicPropertyWrite)
{
[peripheralDevice setNotifyValue:YES forCharacteristic:characteristic];
}
NSLog(@"the property :%d",currentCharacteristic.properties );

这是文档中 Characteristic.properties 的枚举:

typedef NS_ENUM(NSInteger, CBCharacteristicProperties) {
CBCharacteristicPropertyBroadcast = 0x01,
CBCharacteristicPropertyRead = 0x02,
CBCharacteristicPropertyWriteWithoutResponse = 0x04,
CBCharacteristicPropertyWrite = 0x08,
CBCharacteristicPropertyNotify = 0x10,
CBCharacteristicPropertyIndicate = 0x20,
CBCharacteristicPropertyAuthenticatedSignedWrites = 0x40,
CBCharacteristicPropertyExtendedProperties = 0x80,
CBCharacteristicPropertyNotifyEncryptionRequired NS_ENUM_AVAILABLE(NA, 6_0) = 0x100,
CBCharacteristicPropertyIndicateEncryptionRequired NS_ENUM_AVAILABLE(NA, 6_0) = 0x200
};

它可以很好地读取特征值。但问题是在写入值时它不会进入第二个循环。我已将特性设置为可写属性。对于我检查过的两个外围设备,我都得到了 136 in print 语句。请提出一些解决方案来克服这个问题?

最佳答案

通过使用 ANDing 操作解决了这个问题:

 if (characteristic.properties&CBCharacteristicPropertyRead!=0)
{
[peripheralDevice readValueForCharacteristic:characteristic];
}

关于iphone - 核心蓝牙内部的可写特性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16034806/

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