Amogh Shettigar
Amogh Shettigar

Reputation: 285

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];

Upvotes: 0

Views: 986

Answers (2)

Amogh Shettigar
Amogh Shettigar

Reputation: 285

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

Upvotes: 1

Threepwood
Threepwood

Reputation: 41

If you're using Bluetooth Low Energy (without encryption), there is no pairing dialog... You have to implement a pairing by yourself.

You can subscribe to characteristics / get notifications and read from or write to, that's all. You have to implement the corresponding methods from CBPeripheralManagerDelegate. Set the delegate of your peripheralManager and the methods will be called.

See https://developer.apple.com/reference/corebluetooth/cbperipheralmanagerdelegate?language=objc

Upvotes: 0

Related Questions