简体   繁体   English

DidReceiveWriteRequest 在 IOS BLE 中没有被调用

[英]DidReceiveWriteRequest not getting called in IOS BLE

I am trying to send a response from central to peripheral.我正在尝试从中心向外围发送响应。 The code was worked fine twice.该代码两次运行良好。 Suddenly didReceiveWriteRequest is not getting called.突然didReceiveWriteRequest没有被调用。 I didn't make any changes even.The properties given at peripheral are CBCharacteristicsPropertyNotify |我什至没有做任何更改。外围给出的属性是 CBCharacteristicsPropertyNotify | CBCharacteristicsPropertyWriteWithResponse and CBCharacteristicPropertyWrite . CBCharacteristicsPropertyWriteWithResponse and CBCharacteristicPropertyWrite The permissions given are CBAttributePermissionsWriteable | CBAttributePermissionsReadable给定的权限是CBAttributePermissionsWriteable | CBAttributePermissionsReadable CBAttributePermissionsWriteable | CBAttributePermissionsReadable . CBAttributePermissionsWriteable | CBAttributePermissionsReadable At central I have given setNotifyValue=YES in didDiscoverCharacteristicsForService method.在中心,我在didDiscoverCharacteristicsForService方法中给出了 setNotifyValue=YES 。 And this is how I try to write from central:这就是我尝试从中心写作的方式:

[peripheral writeValue:data forCharacteristic:self.peripheralCharacteristicn type:CBCharacteristicWriteWithResponse];

I can't find any mistakes in what I have done.我在我所做的事情中找不到任何错误。 For some reason, didReceiveWriteRequest is not getting called at Peripheral.出于某种原因,没有在外围设备调用 didReceiveWriteRequest。 Please advice.请指教。

I had faced same problem. 我遇到过同样的问题。 Couple of things you can try: 您可以尝试几件事:

  1. From the central side, try changing the 'write to characteristic' API to with response / without response appropriately. 从中心方面,尝试将“写入特征”API更改为响应/无适当响应。

  2. On the peripheral side (which is your iOS device), try using either of the 'didReceiveWrite': 在外围设备端(这是您的iOS设备),尝试使用'didReceiveWrite'之一:

i. 一世。 didReceiveWriteRequests didReceiveWriteRequests

ii. II。 didReceiveWrite didReceiveWrite

iii. III。 didReceiveWriteRequest - Don't miss the singular 'Request' in the name. didReceiveWriteRequest - 不要错过名字中的单数“请求”。 This one receives only one object of CBATTRequest, as opposed to an array of requests in case of the first API 'didReceiveWriteRequests' 这个只接收一个CBATTRequest对象,而不是第一个API'didReceiveWriteRequests'的请求数组

I was stuck with the same issue - my didReceiveWrite callback wasn't being executed.我遇到了同样的问题——我的didReceiveWrite回调没有被执行。 My solution was not just implementing the ".write" CBCharacteristic property, but rather the ".writeWithoutResponse", as on my Central-side (which happens to be a Raspberry Pi running BluePy), my "write" request wasn't requiring a response.我的解决方案不仅仅是实现“.write”CBCharacteristic 属性,而是实现“.writeWithoutResponse”,因为在我的中央端(恰好是运行 BluePy 的 Raspberry Pi),我的“写”请求不需要回复。

The characteristic that works looks something like this:起作用的特征如下所示:

        myChar1 = CBMutableCharacteristic(type: CBUUID(nsuuid: UUID(uuidString: MYUUID)), properties: [.writeWithoutResponse], value: nil, permissions: [.readable, .writeable])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM