蓝牙LE设备从iOS后台扫描 [英] Bluetooth LE Device scan in background from iOS
问题描述
我正在以背景模式扫描BLE。
I am working on to scan BLE in Background mode.
问题在后台扫描中无效。它在前景模式下工作得非常好。
下面是几行代码。
dispatch_queue_t centralQueue = dispatch_queue_create("com.XXXXX.BLEback", DISPATCH_QUEUE_SERIAL);// or however you want to create your dispatch_queue_t
manager = [[CBCentralManager alloc] initWithDelegate:self queue:centralQueue options:nil];
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
if (central.state == CBCentralManagerStatePoweredOn) {
[self startScan];
}
if (![self supportLEHardware])
{
@throw ([NSError errorWithDomain:@"Bluetooth LE not supported"
code:999
userInfo:nil]);
}
}
- (void)startScan
{
NSDictionary * options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:false] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
[manager scanForPeripheralsWithServices:nil options:options];
}
这里我将nil作为服务传递。
我在Xcode中收到登录设备部分。但不是在申请中。
I receive log in Devices section in Xcode. But not in application.
Notice>: (Error) Discovered unknown type for scan: {
kCBAdvDataChannel = 37;
kCBAdvDataIsConnectable = 1;
kCBAdvDataManufacturerData = <00003962 6708f4c1 00000000 00d02b00 20d03300 20d03300 20>;
kCBAdvDataWSaturated = 0;
kCBAdvDataWlanRSSI = 0;
}, -51, puck type: 57
推荐答案
您无法在后台扫描 nil
服务 - 您必须指定您感兴趣的服务。来自 documentation
You cannot scan for nil
services in the background - you must specify the service(s) that you are interested in. From the documentation
指定蓝牙中央后台模式的应用程序是允许在后台扫描的
。也就是说,他们必须通过在
serviceUUIDs参数中指定
来明确扫描一个或多个服务。
Apps that have specified the bluetooth-central background mode are allowed to scan while in the background. That said, they must explicitly scan for one or more services by specifying them in the serviceUUIDs parameter.
这篇关于蓝牙LE设备从iOS后台扫描的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!