Bluetooth LE Device scans in the background from iOS

I am working on scanning BLE in the background.

The problem does not work in the background. It works very well in foreground mode.

Below are a few lines of code.

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]; } 

here i pass zero as services.

I get the log in the Devices section in Xcode. But not in the 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 
+7
ios iphone bluetooth-lowenergy core-bluetooth cbcentralmanager
source share
2 answers

You cannot scan nil services in the background - you must specify the services you are interested in. From the documentation

Applications that indicate the background mode of the bluetooth center are allowed to scan in the background. However, they must explicitly scan one or more services by specifying them in serviceUUIDs.

+10
source share

In order for your application to continue to receive Bluetooth updates in the background, you need to add a UIBackgroundModes entry to your Info.plist and add the bluetooth-central value to the list.

+1
source share

All Articles