Search code examples
iosobjective-ciphonecore-bluetooth

Unable to show the pairing dialog using CoreBluetooth


Hello I am using the Apple Sample BLTE app to show the pairing dialog.(iPhone to iPhone)

This is my code for creating the characteristic

self.transferCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID]
                                                                  properties: CBCharacteristicPropertyRead| CBCharacteristicPropertyNotifyEncryptionRequired
                                                                       value:nil
                                                                 permissions:CBAttributePermissionsReadable];

Above code was taken from one of Apple's articles link

This is my code for when I am notifying and trying to read from the characteristic

if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID]]) {
        [peripheral setNotifyValue:YES forCharacteristic:characteristic];

        [peripheral readValueForCharacteristic:characteristic];
    }

My problem is that when I try this code I dont get a pairing dialog, instead I get this error in didUpdateValueForCharacteristic

2017-04-24 17:24:58.636 BTLE Transfer[1351:457263] Error discovering characteristics: Authentication is insufficient.

Which basically means that I need a pairing to read, but the framework doesn't show the pairing dialog.

What am I doing wrong here? Please help.

EDIT: I updated my characteristic as below:

self.transferCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID]
                                                                  properties: CBCharacteristicPropertyRead| CBCharacteristicPropertyNotifyEncryptionRequired
                                                                       value:nil
                                                                 permissions:CBAttributePermissionsReadEncryptionRequired];

Solution

  • The real problem why the pairing dialog was not showing up was because I had the same iCloud account on both the iphone. The pairing dialog showed up when I removed the account from one device.

    This answer helped me to figure it out link