[英]CoreBluetooth Background Scan Device
I am currently working on an app that requires me to scan a device using Bluetooth 4.0. 我目前正在开发一个需要我使用Bluetooth 4.0扫描设备的应用程序。 At this point I have encounter a problem.
在这一点上,我遇到了一个问题。
Is it possible to have the app scan the device when the app is running in the background? 当应用程序在后台运行时,是否可以让该应用程序扫描设备? For some reason, the app cannot scan the device.
由于某些原因,该应用程序无法扫描设备。 The app did not call didDiscoverPeripheral while it was running in the background.
该应用程序在后台运行时未调用didDiscoverPeripheral。 However, my app can receive data from the device once connection has been establish.
但是,建立连接后,我的应用程序可以从设备接收数据。
To make things simpler, why can't my app scan the device while it is running in the background? 为简化起见,为什么我的应用程序无法在后台运行时扫描设备?
PS I did input the Required background modes 1.App communicates using CoreBluetooth 2.App shares data using CoreBluetooth PS我确实输入了必需的背景模式1.App使用CoreBluetooth进行通信2.App使用CoreBluetooth共享数据
Scanning in the background is a very slow process. 在后台扫描是一个非常缓慢的过程。 Apple says it's 55 times slower than in the foreground.
苹果表示,它比前台慢了55倍。 My experience shows that it can be even slower.
我的经验表明,它可能更慢。 So in order to scan for a device in background keep in mind the following:
因此,为了在后台扫描设备,请注意以下几点:
nil
services. nil
服务。 Put service or data in advertisement package! 将服务或数据放入广告包装中! Also set advertisement periode fast if you want the iPhone to discover it faster.
如果您希望iPhone更快地发现广告,请同时设置广告周期。 I use 20 ms for first 30 s.
我在前30秒使用20毫秒。 br henrik
亨里克
Another thing that may be an issue is that you must scan for specific services, like so: 另一件事可能是问题,您必须扫描特定的服务,例如:
[myCentralManager scanForPeripheralsWithServices:@[serviceUUID] options:nil];
rather than having that "with services" parameter be nil. 而不是将“ with services”参数设为nil。 I think this is a huge gotcha and is barely whispered in Apple's documentation, only mentioned in the description of that method, and nowhere in the Core Bluetooth Backgrounding document.
我认为这是一个巨大的难题,并且在Apple文档中几乎没有低声说过,仅在该方法的说明中提到过,而在Core Bluetooth Backgrounding文档中却没有提及。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.