如何从iOS应用中的Bluetooth LE设备获取通知 [英] How to get notification from Bluetooth LE devices in iOS app

查看:480
本文介绍了如何从iOS应用中的Bluetooth LE设备获取通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发iOS蓝牙LE应用程序.我能够正确并成功遵循的功能如下:

I am working on an iOS Bluetooth LE application. The functionality which I am able to follow correctly and successfully are as follows :

  1. 发现外围设备.
  2. 连接到外围设备.
  3. 获得服务和特征.
  4. 能够在单击读取按钮的同时从特征读取数据.
  5. 能够写数据.

这里我遇到了一个问题,仅当BLE设备将其传输到应用程序时,我才需要读取传入的数据.我正在明确阅读按钮单击时的特征.我的BLE设备以特定的时间间隔连续传输一些数据,但是我无法获取它.

Here I am facing a problem, I need to read incoming data only when the BLE device transmit it to app. I'm explicitly reading the characteristics on button click. My BLE device is continuously transmitting some data in particular intervals, but I am not able to get it.

我在特性上也设置了setNotify,而不是在其上设置成功.

I have set the setNotify as well on characteristics, not success on it as well.

[peripheral setNotifyValue:YES forCharacteristic:characteristic];

如何通过BLE设备事件通知我的应用程序(将其发送到应用程序)? 请在这里帮助我或给我建议.

How can my app be notified by the BLE device event (sending by it to app)? Please help me here or suggest me something.

谢谢.

推荐答案

您正在做什么.来自外围设备的所有数据都将进入didUpdateValueForCharacteristic回调方法.在那找它.

What you are doing should work. All data that arrives from the Peripheral will come to the didUpdateValueForCharacteristic callback method. Look for it there.

因此,无论您显式调用readCharacteristic方法还是只是将外围设备设置为在有可用数据(例如警报或心跳)时通知您,您仍然会在同一位置接收数据.

So whether you explicitly call the readCharacteristic method or just set up your peripheral to notify you when it has data available (like an alarm, or a heart beat), you will still receive the data the same place.

注意:当您发送setNotifyValue消息时,您应该在didUpdateNotificationStateForCharacteristic方法上收到回调,没有错误.如果没有,我建议您检查一下外围固件,并确保该特性不是只读的.

Note: When you do send the setNotifyValue message you should receive a callback on the didUpdateNotificationStateForCharacteristic method with no error. If not, I suggest you look at your Peripheral firmware and make sure that characteristic is not read/write only.

这篇关于如何从iOS应用中的Bluetooth LE设备获取通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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