iOS BLE外设/广告数据在后台模式 [英] iOS BLE peripheral / advertisement data in background mode

查看:166
本文介绍了iOS BLE外设/广告数据在后台模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个系统,它有一个BLE设备(TI CC2540)作为Central,一个iOS应用程序在iPhone4S上作为Peripheral。一切正常,除了我需要的1个功能:来自中心侧的白名单(过滤)广告设备。



据我所知,iOS设备使用随机可解析的MAC地址,所以我们不能根据MAC地址应用白名单。



所以我现在的方法是:在iOS应用程序(iOS)的广告数据上的本地名称字段上输入一个ID设备充当外围设备),中央设备将根据检索到的广告数据进行扫描和过滤。这是有效的,除非应用程序在后台。



当我的应用程序放在后台时,广告数据被截断,我的本地名称不会出现在空中。从corebluetooth的头文件,我看到只有溢出区域数据可以在应用程序处于后台时的广告数据中,但只有iOS设备才能读取该区域。



所以这里的任何人都可以点亮我如何将自定义数据添加到广告包中,即使在后台模式下,或任何其他解决方案都有这种过滤功能。



任何评论都会帮助我非常多。

解决方案

我知道这是一篇较老的帖子,但对于任何好奇的人来说,没有可靠的方法来实现这一点,因为当应用程序在后台时,不会传输CBAdvertisementDataLocalNameKey。



此外,操作系统会忽略CBCentralManagerScanOptionAllowDuplicatesKey,因此您将为每个发现的新设备获得一个didDiscoverPeripheral回调。 / p>

如果您对原因感到好奇,请记住,在硬件级别,只有一个蓝牙无线电由所有使用BLE的应用共享,并且ertisement数据包在所有广告应用之间共享。



溢出区域包含设备通告的所有服务UUID。我想这个领域很小,系统可能必须发送几个循环通过UUID的数据包来宣传它们全部,如果你有很多。



此外,这里是广告包是放置所需应用信息的非最佳位置的另一个原因。假设您有一个依赖于服务UUID A的广告数据的应用程序。然后,该应用程序变为后台,用户打开另一个使用服务UUID B的广告数据的应用程序。



因为设备现在为UUID A和UUID B提供广告服务,所以任何接收设备都会在任何中心寻找A或B进行回调。但是,
CBAdvertisementDataLocalNameKey将只包含B的数据,因为它位于发送设备的前台,这意味着您的设备只期望A的数据可能正在处理错误的数据。



如果你想更清楚一点广告数据实际传输的是什么,App Store上有一个名为LightBlue的优秀iOS应用程序会向您显示这些数据,并允许您连接到设备并查看其所有服务,特征和描述符。


I'm developing a system which has a BLE device (TI CC2540) as Central and an iOS app on iPhone4S as Peripheral. Everything works fine except 1 function I need: white-list (filtering) advertising devices from central side.

As far as I know, iOS devices use Random Resolvable MAC address, so we cannot apply white-list based on MAC address.

So my current method is: put an ID on "Local name" field on advertisement data of iOS app (iOS device acts as peripheral), Central device will scan and filter based on retrieved advertisement data. This works unless app is in background.

When my app is put in background, advertisement data is truncated and my "local name" does not appear over-the-air. From header file of corebluetooth, I see there is only "overflow area" data can be in advertisement data when app is in background, but only iOS device can read this area.

So can anybody here light me how to add custom data into advertisement packet even in background mode, or any other solution to have this filtering function.

Any comment will help me very much.

解决方案

I know this is an older post, but for anybody curious, there is no reliable way to accomplish this because the CBAdvertisementDataLocalNameKey not transmitted while the app is in the background.

Also, the OS ignores the CBCentralManagerScanOptionAllowDuplicatesKey, so you will get exactly one didDiscoverPeripheral callback for each new device discovered.

If you are curious as to why, remember that at the hardware level there is only one bluetooth radio that is shared by all the apps using BLE, and the advertisement packet is shared among all the apps that advertising.

The overflow area holds all the service UUID's that your device advertises. I would imagine that this field is small and the system likely has to send out several packets cycling through the UUID's to advertise them all, if you have many.

Also, here is one more reason why the advertisement packet is a non-optimal place to put required app information. Say you have an app that relies on advertisement data for service UUID A. Then, that app becomes backgrounded and the user opens up another app that uses advertisement data for service UUID B.

Because the device is now advertising services for UUID A and UUID B, any receiving device will get a callback on any central looking for an A or B. However, the CBAdvertisementDataLocalNameKey will only contain the data for B, since it is in the foreground on the transmitting device, which means your device is only expecting data for A could be processing the wrong data.

If you want to get a clearer at what the advertisement data is actually transmitting, there is an excellent iOS app on the App Store called LightBlue will show you this data, and allow you to connect to a device and look at all it's services, characteristics and descriptors.

这篇关于iOS BLE外设/广告数据在后台模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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