• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Central manager callback didDiscoverPeripheral twice
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Central manager callback didDiscoverPeripheral twice


  • Subject: Central manager callback didDiscoverPeripheral twice
  • From: Christian Wilhelmsen <email@hidden>
  • Date: Fri, 20 Jul 2012 14:04:31 +0200

I scan for my peripheral like this:

 

    NSDictionary *scanOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]
                                                                forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
            // Scan for peripherals with given UUID
            [cm scanForPeripheralsWithServices:[NSArray arrayWithObject:Controller.serviceUUID] options:scanOptions]

 

No problem there, I find the peripheral and are able to connect to it. I also give it the parameter to not scan for more than one peripheral (CBCentralManagerScanOptionAllowDuplicatesKey FALSE), but sometimes the `didDiscoverPeripheral`callback fires twice.

- (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");
    }
}

Some times I get

 

Discovered
Already discovered

as output in my console, and most of the times only the `Discovered` message shows.

In my peripherals delegate I have

 

 

- (void) peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error{

    NSLog(@"Did discover services on peripheral %@", [peripheral name]);

    for (CBService *s in [peripheral services]){

        // DOES NOT ENTER THIS LOOP WHEN didDiscoverPeripheral FIRE TWICE 
        if ([[s UUID] isEqual:Controller.serviceUUID]){
            NSLog(@"Found service on %@", [peripheral name]);
            self.service = s;

            [peripheral discoverCharacteristics:[NSArray arrayWithObject:Controller.throttleCharacteristicUUID] forService:self.service];

        }
    }

        if (self.service == nil){ // THIS HAPPENS WHEN didDiscoverPeripheral FIRE TWICE
        [delegate didDiscoverCharacteristic:NO];
    }

}

 

 

When both occur (didDiscover twice) I am unable to establish the connection, since the for loop is not running as expected (self.service = nil). It works if I reboot the phone again.

I could also wipe out all stored data from previous connections before running my application, and as far as I know, this can only be done by rebooting the phone. Is there any other way, preferably programatically, to do this? I desperately need to figure this out.

 

Thank you very much in advance

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Central manager callback didDiscoverPeripheral twice
      • From: Joakim Linde <email@hidden>
  • Prev by Date: Using the iPhone as a Peripheral
  • Next by Date: Re: Central manager callback didDiscoverPeripheral twice
  • Previous by thread: Using the iPhone as a Peripheral
  • Next by thread: Re: Central manager callback didDiscoverPeripheral twice
  • Index(es):
    • Date
    • Thread