IOS发展署:背景BLE扫描 [英] IOS Developpement : Background BLE scanning

查看:375
本文介绍了IOS发展署:背景BLE扫描的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在试图建立一个背景蓝牙相关的应用程序,我有在后台一些麻烦扫描。

I'm currently trying to develop a Background Bluetooth related app, and I'm having some trouble scanning in background.

我跟着整个苹果iOS蓝牙背景的教程,但我无法弄清楚,为什么扫描不在后台运行(我info.plist中正确设置管理BLE后台任务,中枢和外周)。

I followed the entire Apple IOS Bluetooth Background tutorial, but I cant figure out why scanning doesn't work in background (my info.plist is correctly set up to manage BLE Background tasks, both central and peripheral).

我到目前为止已经进行测试:

What I've tested so far :

1 - 当我的两个设备都在范围和前景,扫描效果很好。

1 - When my two devices are in range and in foreground, scanning works well.

2 - 当外设在后台,并在前台中央自带活跃,扫描也适用,外设以及检测。

2 - When the peripheral is in background, and the central comes active in foreground, scanning also works, peripheral is well detected.

这里说到的烦恼

3 - 首先启动我的外围设备,我把应用程序在后台运行。然后,外围设备上,我的电源关闭蓝牙后,我启动应用程序,我把它放在后台,我开机蓝牙。
在我的code时, - (无效)centralManagerDidUpdateState:(CBCentralManager *)中心调用扫描 [centralmgr scanForPeripheralsWithServices:[NSArray的arrayWithObject:servicesUUID ]选项:scanOptions]; ,功能,在前台完美。但是什么都没有发生,周围是永远不会由中央检测。

3 - first I launch my peripheral device, and I put the app in the background. Then on the peripheral device, I power off the bluetooth, I launch the app, I put it in background, and I power on the bluetooth. In my code, the -(void)centralManagerDidUpdateState:(CBCentralManager *)central calls the scan [centralmgr scanForPeripheralsWithServices:[NSArray arrayWithObject:servicesUUID] options:scanOptions];, function which works perfectly in the foreground. But nothing happened, the peripheral is never detected by the central.

4 - 我启动了中央,蓝牙激活的,我把它的背景。然后,我把我的外围设备,我出去了蓝牙范围内的的(在我去了我超市的具体情况购买一些啤酒淹没我的悲伤)的,我启动它有 - 也蓝牙activated-我把它放在背景和我在周边附近回来。再一次什么都没有发生,则切牙没有检测到外围。

4 - I launch the central, bluetooth activated, and I put it in background. Then I took my peripheral device, I went out of the bluetooth range (in the specific case I went to my supermarket to buy some beers to drown my sorrow), I launch it there -also bluetooth activated- I put it in background and I came back in the proximity of my peripheral. Once again nothing happened, the centrals did not detect the peripheral.

此外,例3和4,如果我只是把中央的前景(外围背景住宿),检测重启,无需做其他事情了。至于如果被扫描的情况下成功4引发的,而是在等待应用程序来主动到真正开始检测其他设备。

Furthermore, after the cases 3 and 4, if I just put the central on the foreground (the peripheral stays in background), detection restart, without doing anything else. As if the scan was successfully triggered in the case 4, but waiting the app to come active to actually start detecting other devices.

是否有人对如何进行一个想法/解决这个问题?

Does somebody have an idea on how to proceed/overcome the problem?

感谢您!

PS:我appologize我的英语水平,我是一个有点生疏

Ps: I appologize for my English, I'm a bit rusty

推荐答案

嗨详情你可以看到这回答

但简单的答案是您的应用程序之一,必须在前台以相互连接
无论您的中央设备或外围

but the short answer is one of your Apps must be in Foreground to connect to each other Either your central device or the peripheral

原因:作为中央您提供外设服务的UUID独扫描

Reason: for central you an only scan with providing the service UUIDs of the peripheral

和背景外设不能adverise它的UUID
所以即使他们在那里他们只是不知道对方的presence

and in background a peripheral cannot adverise its UUIDs so even they are there they just don't know of each others presence

另外一些关于后台扫描更为显着的东西。

Moreover some more notable things about background scanning are

您应该知道,广告,而你的应用程序在后台运行时相比,您的应用程序在前台操作方式有所不同。特别是,当您的应用程序在后台,而广告:

you should be aware that advertising while your app is in the background operates differently than when your app is in the foreground. In particular, when your app is advertising while in the background:

CBAdvertisementDataLocalNameKey 广告按键被忽略,和周边的本地名称不通告。

The CBAdvertisementDataLocalNameKey advertisement key is ignored, and the local name of peripheral is not advertised.

包含在 CBAdvertisementDataServiceUUIDsKey 广告键值所有服务的UUID被放置在一个特殊的溢出区;他们只能通过显式扫描他们的iOS设备被发现。

All service UUIDs contained in the value of the CBAdvertisementDataServiceUUIDsKey advertisement key are placed in a special "overflow" area; they can be discovered only by an iOS device that is explicitly scanning for them.

如果说广告是所有的应用程序都在后台的频率,你的外围设备发送广告的数据包可能会下降。

If all apps that are advertising are in the background, the frequency at which your peripheral device sends advertising packets may decrease.

<一个href=\"https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html\"相对=nofollow>见苹果文档

这篇关于IOS发展署:背景BLE扫描的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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