1
votes

When an app running on iOS8 is backgrounded, all uniquely identifiable information appears to be scrubbed from the Bluetooth advertising package. peripheral.name, peripheral.identifier, etc. It all goes away as soon as the app is backgrounded.

The only workaround I have discovered - to identify and range multiple bluetooth-emitting apps - is to scan and connect with a set of known devices (iPhones).

My app transmits as a peripheral, with a service that has a characteristic whose value is a unique identifier. This works.

Where I fall down is once I have read the characteristic (and identified the device) I need to range it. In the delegate call for did get RSSI, I get a peripheral object, but due to the asynchronous nature of the delegate pattern I don't know which of the discovered peripherals I am getting the RSSI signal for. Peripheral appears to remain anonymous, even after connected!

-(void) peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
if (error == nil) { NSString *valueString=[[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding]; NSLog(@"The new value=%@",valueString); peripheral.delegate = self; [peripheral readRSSI]; } }

-(void) peripheral:(CBPeripheral *)peripheral didReadRSSI:(NSNumber *)RSSI error:(NSError *)error { NSLog(@"Got RSSI update in didReadRSSI : %4.1f", [RSSI doubleValue]); // but which peripheral (and associated id) did we get back?? }

This is either a limitation of Apple's spec, or something wrong with my expectations. One central to many peripherals, unlike the original Bluetooth architecture of one-to-one.

Any ideas how I can identify and range an app broadcasting as a peripheral while backgrounded? Huge thanks if so!

1

1 Answers

0
votes

The CBPeripheral object itself should be unique. You can keep a dictionary of your discovered / connected peripherals along with the custom identifier from your characteristic. When the didReadRSSI delegate is called, you can check against your 'known' collection of devices to identify a specific device.