Hi all,
Im using CoreBluetooth framework to
discover the BLE device running in pure broadcaster role on
iPhone 4S.
The problem is: the code works fine when it
runs in the foreground. But the advertisement of the BLE
device is not able to discovered when the application is
switched to the background (didDiscoverPeripheral is never
called). The application comes back to find advertisements
when it is switched back from the background to the
foreground.
According to the thread How
to make BLE app work on background of iPhone4S, it is
supported to do scanning in the background. And I did add the
background mode entry bluetooth-central to
UIBackgroundModes in the apps info.plist. And the code doing
scan is as below:
NSDictionary *options = [NSDictionary
dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:TRUE],
CBCentralManagerScanOptionAllowDuplicatesKey, nil];
[self.CM scanForPeripheralsWithServices:nil
options:options];
And in the didDiscoverPeripheral delegate,
the UI is updated through the code in another class like:
If([NSThread isMainThread] == true) {
[self updateScanningStatus];
}
else {
[NSObject
performSelectorOnMainThread:@selector(updateScanningStatus)
withObject:nil waitUntilDone:No];
}
Hope someone here could help me to figure
the root cause of the problem.
Thanks,
Kai