I am using Bluetooth LE on iPhone 5S and I have done the following:
I have a bluetooth peripheral and I have configured it to advertise each 20th ms on all three bluetooth advertising channels (37, 38 and 39).
I have configured my app with UIBacgroundModes = bluetooth-central in Info.plist
I have started a scanForPeripheralsWithServices like below
Code:
NSDictionary *options = @{
CBCentralManagerOptionRestoreIdentifierKey:@"myCentralManagerIdentifier",
CBCentralManagerScanOptionAllowDuplicatesKey:[NSNumber numberWithBool:YES]
};
self.manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:options];
[self.manager scanForPeripheralsWithServices:[NSArray arrayWithObject:[CBUUID UUIDWithString:@"<uuid removed>"]] options:options];
The current state is:
In foreground mode the app quickly receives advertisement messages when I start my peripheral (within one second)
In background mode the app sometimes receives advertisement messages within like 10 seconds after starting the peripheral (which can be acceptable even if it is bad) however often it does not receive the advertisement for a very long time (minutes or more) and this does not work for the application.
Question is:
Is it in some way possible to increase the rate of which iOS is scanning for Bluetooth 4.0 LE peripherals when the scanning app is in background? Since I don't think there is a public API to do this, I am looking for a private API that is not published by Apple. This is for an internal enterprise app so a private API would be perfectly OK.
Background mode works differently for scanning.
Every peripheral is only reported the first single time it is observed (you cannot track proximity through RSSI without connecting to it while in background mode).
You can initiate a connect request to a peripheral that's not within range, and the connection will complete when the peripheral becomes available. Don't have to actively scan for this (except for initial discovery, so you know which UUID to connect).
Maybe, you can solve the problem by sending a connect request instead of scanning, while in background. This way, iOS knows that you are really interested in a specific peripheral and I could imagine that this affects discovery times.
Depending on your goal, a different approach could be to reverse the connection by placing the iPhone in peripheral mode and using your current LE peripherals in central mode. Seems hackish, but if it solves the problem for your case: why not :)
Regarding a private API: sorry, I don't know one that affects scanning parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With