gpt4 book ai didi

ios - 外设写入值: forCharacteristic: type: return null error and value

转载 作者:行者123 更新时间:2023-12-02 20:03:10 24 4
gpt4 key购买 nike

我正在使用Apple编写的以下代码。

https://developer.apple.com/library/mac/samplecode/HeartRateMonitor/Listings/HeartRateMonitor_HeartRateMonitorAppDelegate_m.html#//apple_ref/doc/uid/DTS40011322-HeartRateMonitor_HeartRateMonitorAppDelegate_m-DontLinkElementID_4

这是Apple编写的writeValue部分

if ([aChar.UUID isEqual:[CBUUID UUIDWithString:@"2A39"]])
{
uint8_t val = 1;
NSData* valData = [NSData dataWithBytes:(void*)&val length:sizeof(val)];
[aPeripheral writeValue:valData forCharacteristic:aChar type:CBCharacteristicWriteWithResponse];
}

我添加了 didWriteValueForCharacteristic

- (void) peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{
NSLog(@"Did write characteristic value : %@ with ID %@", characteristic.value, characteristic.UUID);
NSLog(@"With error: %@", [error localizedDescription]);
}

didWriteValueForCharacteristic 的打印输出如下:

Did write characteristic value : (null) with ID Unknown (<2a39>)
With error: (null)

我使用了两种不同的心脏监视器和蓝光应用程序(模拟 ble 设备),但得到了相同的结果。

为什么 didWriteValueForCharacteristic 的值和错误返回 null?

最佳答案

您看到的是该特征的最后读取值。由于您以前从未读过它,因此它是nil。您需要使用 readValueForCharacteristic: 方法显式读取该值,以使其在中心端更新。

关于ios - 外设写入值: forCharacteristic: type: return null error and value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23461061/

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