Hi Bob,
Thank you for the information!
I don’t see the requirements of not null serviceID array in CoreBluetooth document for scanForPeripheralsWithServices works in the background. I can understand if it is required for saving power by not bothering the application with
non-relevant BLE devices.
But the interesting thing is that for a device running in broadcaster role, it does not implement any service. I’m not sure if it works in the background by including service UUID AD type in the BLE device’s advertisement and use the
UUID to do filtering with scanForPeripheralsWithServices. I can take a try to see if it works and any insight/comment is appreciated!
Thanks,
Kai
>hi kai,
>
>correct me if i'm wrong, but i believe you need to pass an array of (at least one) service IDs to 'scanForPeripheralsWithServices'.... passing 'nil' will indeed work in the foreground, but not in the background as i understand it....
>
>bob.
>On 2/15/2012 2:43 AM, Kai Wang (STC) wrote:
>>
>> Hi all,
>>
>> I'm 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"
>> <http://lists.apple.com/archives/bluetooth-dev/2011/Dec/msg00012.html>
>>, it is supported to do scanning in the background. And I did add the
>>background mode entry "bluetooth-central" to UIBackgroundModes in
>>the app's 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
>>