3

is it possible to get the users decision of the bonding request of iOS?

  • Choice 1: Abbort
  • Choice 2: Connect/Bond

Screenshot of Bonding-request: enter image description here

I tried to use the centralManagerDidUpdateState, but it is called only one time with CBManagerStatePoweredOn if I turn Bluetooth on.

#pragma mark - CBCentralManagerDelegate
- (void)centralManagerDidUpdateState:(CBCentralManager *)central {

    info(@"centralManagerDidUpdateState");

        switch(central.state){

            case CBManagerStateUnauthorized:
                info(@"unauthorized");
                break;

            case CBManagerStatePoweredOff:
                info(@"poweredOff");
                break;

            case CBManagerStatePoweredOn:
                info(@"poweredOn");
                break;

            case CBManagerStateResetting:
                info(@"resetting");
                break;

            case CBManagerStateUnknown:
                info(@"unknown");
                break;

            case CBManagerStateUnsupported:
                info(@"unsupported");
                break;
        }
}

I also tried to use "didConnectPeripheral" and "didFailToConnectPeripheral":

- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
    [peripheral setDelegate:self];
    [self _cancelConnectionRequests];
    [peripheral discoverServices:nil];

    BleDevice* bleDevice = [knownDevices findDevice:[peripheral.identifier UUIDString]];
    devicePaired(bleDevice.deviceId, bleDevice.primaryServiceUuid);
}

- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
    [peripheral setDelegate:self];
    [self _cancelConnectionRequests];
    [peripheral discoverServices:nil];

    BleDevice* bleDevice = [knownDevices findDevice:[peripheral.identifier UUIDString]];
    deviceNotPaired(bleDevice.deviceId, bleDevice.primaryServiceUuid);
}

But both methods are not called after clicking on "Abort" or "Connect/Bond"! At least only "didConnectPeripheral" is called while trying to connect to the device - but this happens before the popup comes up!

Any other ideas?

Note: I have no problems with scanning, connecting or bonding with a BLe device - I only want to know if the user accepted the bonding-request from his iPhone!

SbstnErb
  • 101
  • 1
  • 8

1 Answers1

2

No it's not possible. I don't know why Apple made this decision since from a security point of view it might be important for the app to know if the link is properly encrypted and authenticated.

If you can control the firmware of the peripheral you can make it send something on a characteristic when pairing events happen.

Emil
  • 16,784
  • 2
  • 41
  • 52
  • >>> If you can control the firmware of the peripheral you can make it send something on a characteristic when pairing events happen. <<< Yes, I do - but exactly this is the thing I wanted to avoid. pity... Well, thanks so far! – SbstnErb Feb 22 '17 at 08:09