Listing Bluetooth Devices Natively In Objective-C

Using bluetooth with Objective-C can be achieved with the IOBluetooth framework.

An example of some useful classes for basic operation are:

  • IOBluetoothDevice
    • connection methods
    • [IOBluetoothDevice pairedDevices] returns an NSArray of paired devices
    • alot of other stuff
  • IOBluetoothDeviceInquiry
    • looks for available devices
  • IOBluetoothHostController
    • the powerState property can tell you if your own bluetooth is on or off

Here is some example code for using IOBluetoothDeviceInquiry to get the address of each bluetooth device in range. Start the inquiry process with something like:

IOBluetoothDeviceInquiry *inquirer = [IOBluetoothDeviceInquiry inquiryWithDelegate:self];
// Configure further here if necessary
[inquirer start];

Now, you can get the address of the found devices using the IOBluetoothDeviceInquiryDelegate methods:

#pragma mark - IOBluetoothDeviceInquiryDelegate Methods

- (void) deviceInquiryComplete:(IOBluetoothDeviceInquiry *)sender error:(IOReturn)error aborted:(BOOL)aborted {
    NSArray *devices = [sender foundDevices];
    for (IOBluetoothDevice *device in devices) {
        const BluetoothDeviceAddress *address = [device getAddress];
        // Do something with address
    }
    [sender performSelector:@selector(start) withObject:nil afterDelay:7];
}

The following Mac Dev Center reference maybe of interest to you. It is a little in depth but does have code examples.

Introduction to Bluetooth Device Access Guide