Note that there are some explanatory texts on larger screens.

plurals
  1. POCorebluetooth central manager callback didDiscoverPeripheral twice
    primarykey
    data
    text
    <p>I scan for my peripheral like this:</p> <pre><code>NSDictionary *scanOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey]; // Scan for peripherals with given UUID [cm scanForPeripheralsWithServices:[NSArray arrayWithObject:HeliController.serviceUUID] options:scanOptions] </code></pre> <p>No problem there, I find the peripheral and are able to connect to it. As you can see I give it <code>CBCentralManagerScanOptionAllowDuplicatesKey</code> with <code>bool NO</code> to not allow for more than one peripheral, but sometimes the <code>didDiscoverPeripheral</code>callback fires twice. </p> <pre><code>- (void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI { if(!discovered){ discovered = YES; NSLog(@"Discovered"); [cm stopScan]; [scanButton setTitle:@"Connect" forState:UIControlStateNormal]; } else if(discovered){ discovered = YES NSLog(@"Already discovered"); } } </code></pre> <p>Some times I get </p> <pre><code>Discovered Already discovered </code></pre> <p>as output in my console, and most of the times only the <code>Discovered</code>message shows. </p> <p>In my peripheral delegate I first discover services, which then call <code>[peripheral discoverCharacteristics</code> and the callback always occurs:</p> <pre><code>- (void) peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error{ NSLog(@"Did discover characteristic for service %@", [service.peripheral UUID]); for(CBCharacteristic *c in [service characteristics]){ // We never get here when peripheral is discovered twice if([[c UUID] isEqual:myCharacteristicUUID]){ NSLog(@"Found characteristic"); self.throttleCharacteristic = c; } } </code></pre> <p>When <code>didDiscoverPeripheral</code> occur twice, <code>service</code> becomes <code>nil</code>in this method, even though <code>peripheral</code> is not (UUID, name is still correct). </p> <p>Rebooting the phone or resetting the network settings fixes the problem temporarily. </p> <p>I really need to get this fixed! Thank you</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload