Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

aelinden

macrumors newbie
Original poster
Jan 16, 2012
5
0
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:
Code:
- (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:

Code:
[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;
    }
    else
    {
        return false;
    }
}
[/SIZE]

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:
Use the IOBluetoothDevicePair object to attempt to pair with any Bluetooth device. Once -start is invoked on it, progress is returned to the delegate via the messages defined below. This object enables you to pair with devices within your application without having to use the standard panels provided by the IOBluetoothUI framework, allowing you to write custom UI to select devices, and still handle the ability to perform device pairings.

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
dubblarutor.png

(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?
 
Last edited:
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.
 
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:
Indicates to the delegate that the pairing object has made the device (baseband) connection and is
awaiting the a yes/no answer for the Simple Secure Pairing numeric comparison. Thus, when you recieve this message,
you should display to the user the numeric value and then accept the yes/no answer if it matches the value
on the other device.

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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.