我正在扫描硬件设备。在前台时,我可以看到设备。当我在前台开始扫描,然后移动到后台,然后我打开硬件-BLE,扫描停止,应用程序无法检测到硬件。
如果我打开应用程序返回到前台,它会继续扫描并找到设备。
我已经设置了关键点:
<string>bluetooth-peripheral</string>
<string>bluetooth-central</string>还有背景模式:
location updates
external accessory communication
uses BLE accessories
acts as BLE ACCESSORY但是什么都没有。系统不让我在后台检测设备,只让我在前台检测。
我错过了什么?
发布于 2014-11-25 02:31:45
我发现你必须设置你在后台寻找的服务id,否则它将无法工作。无论如何,在后台扫描是非常慢的和可能需要几分钟来检测!!
[_centralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:DEVICE_INFO_SERVICE_UUID]]发布于 2016-08-31 19:16:21
你只能在后台扫描特定的serviceUUID,你可以通过传递nil来扫描,就像我们在前台扫描一样。
此外,请确保在主线程中启动BLE扫描,并设置正确的选项,如下所示。
NSArray *services = @[[CBUUID UUIDWithString:UUID1],[CBUUID UUIDWithString:UUID2],[CBUUID UUIDWithString:UUID3]];
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreBluetoothManager scanForPeripheralsWithServices:services options:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], CBCentralManagerScanOptionAllowDuplicatesKey, nil]];
});https://stackoverflow.com/questions/27111338
复制相似问题