Bluetooth pairing

Discussion in 'Mac Programming' started by aelinden, May 3, 2012.

  1. aelinden, May 3, 2012
    Last edited: May 3, 2012

    aelinden macrumors newbie

    Jan 16, 2012
    The application I'm working with is used to connect phones via Bluetooth to a computer and control the phone that way. I've come across an issue when it comes to pairing devices.

    The program uses wxWidgets with its own UI (It's made for people with disabilities) and so I don't want to use the native Mac controls for pairing a device with the computer. The way I'm doing things now are as follows:

    I have a phone manager class is called from the UI. The phone manager implements the delegate methods:
    - (void) devicePairingStarted:(id)sender;
    - (void) devicePairingUserConfirmationRequest:(id)sender numericValue:(BluetoothNumericValue)numericValue;
    - (void) devicePairingFinished:(id)sender error:(IOReturn)error;
    When a user wants to pair a device (A bluetooth inquiry has already been performed at that point) this function is called:

    [SIZE="2"]- (bool) pairWithDevice:(std::string)device_address_string
        BluetoothDeviceAddress btaddr = [self stringToAddress:device_address_string];
        m_pairing = [IOBluetoothDevicePair pairWithDevice:[IOBluetoothDevice deviceWithAddress:&btaddr]];
        [m_pairing setDelegate:self];
        [m_pairing replyUserConfirmation:true];
        if([m_pairing start] == kIOReturnSuccess)
            return true;
            return false;
    Basically I start a pairing attempt with the phone manager as delegate (The stringToAddress function simply converts a std::string send from the UI to a BluetoothDeviceAdress).

    When the user has to confirm the pairing PIN-code, the function devicePairingUserConfirmationRequest is called which in turn calls a function in the UI that displays the PIN-code and asks the user if the code on the monitor matches the one on the phone. When the accepts the PIN, the UI calls a function pinIsCorrect (written by myself) in the phone manager which in turn calls the function replyUserConfirmation as is required according to the documentation. When the pin is accepted, the pairing finishes and the phone can now be connected to.

    This all works as it should but for one issue. When I show the dialog asking the user to accept or reject the PIN, the native Mac dialog suddenly also shows up and asks the same question. Why is this and is there a way I can make it not show up?

    The documentation for IOBluetoothDevicePair says:
    So as I understand it, I should be able to do this pairing without any standard Mac panels showing at all. For some reason the OS X PIN confirmation dialog is still shown. If anyone can give me a hint on how to make it not show, it would be appreciated.

    Update: Added a picture to make things clearer
    (The text is in Swedish if anyone is wondering)

    As you can see, both the OS X confirmation dialog and my own dialog is showing. Now how do I NOT show the OS X one?
  2. numero macrumors regular

    Jul 23, 2002
    I did a Blackberry bluetooth application about 2 years ago. My recollection from that was I had a prerequisite for the use of the program that the hardware was already paired with the phone. I think I came to this decision because of the security requirements of bluetooth. It is not possible to silently pair devices. I think the OS is putting up this dialog because it isn't sure that you are notifying the user.

    Again. I did this over 2 years ago. I'm going from memory. I know I talked about Blackberry and not iPhone and I didn't address your delegate methods, but I think you are running into a Bluetooth system issue and not an iPhone development problem.
  3. aelinden thread starter macrumors newbie

    Jan 16, 2012
    Thanks for the reply. Too bad it won't really help me though :)

    If you are right that the system doesn't see that I am notifying the user then the Apple Bluetooth documentation needs a serious overhaul. It mentions nothing about that issue.

    The documentation (And the header file) simply states that in devicePairingUserConfirmationRequest:numericValue:, the method replyUserConfirmation must be invoked. It also says:
    This is what I'm doing! In devicePairingUserConfirmationRequest:numericValue: I show my own dialog with the number that accepts a yes or no answer. This answer is then sent with the replyUserConfirmation method.

    I guess what you mean is that the system doesn't know that I'm displaying my own dialog and so it shows its own, but why then would the documentation say that I can use the IOBluetoothDevicePair class to perform pairing without using the standard panels? It makes no sense. Am I missing a crucial step somewhere or is the bluetooth documentation just not very good?

Share This Page