IOS 8.0 bluetooth peripheral manager does not give callback for addService

I have created a bluetooth peripheral manager. I am adding some services to this peripheral manager using [self.peripheralManager addService: myService].

For iOS7.0 I get a callback for this method - (void): peripheral admin: (CBPeripheralManager *) peripheral didAddService error: (CBService *): (NSError *) error

But for iOS8.0 I am not getting any callback for the same method and I am unable to establish a connection.

Below are the steps I followed:

  • Create a peripheral manager using [[CBPeripheralManager alloc] initWithDelegate: self queue: nil options: @ {CBPeripheralManagerOptionShowPowerAlertKey: @YES}];

2.Create a service using myService = [[CBMutableService alloc] initWithType: [CBUUID UUIDWithString: @ "AAAA"] primary: YES];

  1. Create a characteristic using myCharacteristic = [[CBMutableCharacteristic alloc] initWithType: [CBUUID UUIDWithString: @ "BBBB"] properties: CBCharacteristicProperty Indicative value: nil permissions: CBAttributePermissionsReadable];

  2. Add this trait to your service using myService.characteristics = characteristic

  3. Add this service to the peripheral manager using [peripheralManager addService: myService];

  4. The callback for this above step happens in

    • (void) peripheralManager: (CBPeripheralManager *) peripheral error didAddService: (CBService *): (NSError *) error;
  5. In iOS8, we don't receive this callback.

The code for the peripheral manager changed the update state below.

-(void) peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral{
    NSLog(@"Changed State : %d", peripheral.state);
    if (peripheral.state != CBPeripheralManagerStatePoweredOn) {
        [self deviceDisconnected];


I am adding a service using:

[self.peripheralManager addService: myService];

Is this method deprecated in iOS8.0, or could this error be due to some other reason?


source to share

1 answer

@Paulw answered this correctly in the comments. Below is the answer

There is a change between ios7 and ios8 in that ios7 operations are allowed before the bluetooth hardware has been initialized (power on state) and warning is issued. In ios8, it just fails.

Thus, we have to wait for the callback peripheralManagerDidUpdateState:

before adding any service.



All Articles