以值null调用的CoreBlueTooth委托didWriteValueForCharacteristic [英] CoreBlueTooth delegate didWriteValueForCharacteristic called with a value null

查看:91
本文介绍了以值null调用的CoreBlueTooth委托didWriteValueForCharacteristic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将notify设置为一个特征,然后将一些数据(这是要读取的地址和读取的数据长度)写入另一个特征。将调用didUpdateValueForCharacteristic委托,但character.value为零(应具有某个值)且长度正确。
我还要检查委托didWriteValueForCharacteristic。在写入数据后将调用此方法,但是在委托中,feature.value为null,而feature.UUID与我编写的相同。

I set notify to a characteristic, and then write some data(It's the address to be read and read data length) to another characteristic. Delegate didUpdateValueForCharacteristic will be called, but the characteristic.value is zero (should have some value) with the correct length. I also check the delegate didWriteValueForCharacteristic. This will be called after I write the data, but in the delegate, characteristic.value is null while the characteristic.UUID is the same as I wrote.

因此,当didWriteValueForCharacteristic已被正确调用,是否表示写操作成功?如果是这样,为什么特征值为null?(我认为该值应等于我在writeValue中写的内容:forCharacteristic:type:)

So when didWriteValueForCharacteristic has been called without error, does it means the write operation is successful? If so, why is characteristic value null?(I think the value should equal to what i wrote in writeValue: forCharacteristic:type:)

推荐答案

我已经遇到了您在这里遇到的类似问题,所以我将尝试分享我所看到的内容。

I've been running into similar issues that you have been experiencing here so I will try to share what I've seen.

didWriteValueForCharacteristic不是您所需要的当您尝试从外围设备获取数据时需要。尽管您说要在某个地方写数据,但我不确定这与获取更新通知有什么关系。

didWriteValueForCharacteristic isn't what you want when you are trying to get data from a peripheral. Although you say you are trying to write data somewhere, I'm unsure what that has to do with getting an update notification.

如果您使用的是notify设置,则您应该专注于didUpdateValueForCharacteristic。

If you are using the notify setting, then you should focus on didUpdateValueForCharacteristic.

在调用didUpdateValueForCharacteristic时,并不一定意味着值已完全传达。您必须记住,要发送的数据只能少量发送(如果我没记错的话,只能发送20个字节),因此在某些情况下,您正在查看的数据可能不完整。

When didUpdateValueForCharacteristic is called it doesn't necessarily mean that a value has been completely conveyed. You have to keep in mind that the data being sent can only be sent in small amounts (20 bytes, if I remember correctly), so there could be a case where the data that you are looking at is incomplete.

我注意到的另一件事是,当您致电

Another thing that I have noticed is that on the peripheral side when you call

 [peripheralManager updateValue:dataToSent forCharacteristic:aCustomCharacteristic onSubscribedCentrals:nil];

它返回一个BOOL,告诉您数据是否已成功发送。如果未成功发送,则它将停止尝试发送后续的消息,这可能会很麻烦。

it returns a BOOL which tells you whether or not the data was successfully sent. If it is not successfully sent then it stops trying to send subsequent ones, which can be a pain.

当我尝试从外围设备发送int值作为数据时客户端,我正在使用iPad和iPhone。当iPhone是客户端而iPad是外围设备时,我遇到了问题。我得到的空值很像您要处理的值,但是当我切换两个值时,我得到了应该得到的正确值。这也可能与您使用的设备有关,因为我不确定您是否可以使用iPad外围设备。

When I was trying to send an int value as data from a peripheral to a client, I was using an iPad and an iPhone. I had issues when the iPhone was the client and the iPad was the peripheral. I got the null values much like what you were dealing with, but when i switched the two, I got the proper values I was supposed to get. It could also be an issue with your devices that you are using, as I am not completely sure you can use an iPad a peripheral.

这篇关于以值null调用的CoreBlueTooth委托didWriteValueForCharacteristic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆