1

The Question

I'm writing an app for a Bluetooth peripheral, and I want to pair the peripheral to the iPhone directly in my app, without asking the user to go the Settings app and do the pairing manually. I see the "Sony Headphones Connect" app does exactly that, and I want the same ability in my app. I can't find anything for doing this in Core Bluetooth. Any idea?

Further Info

Here's what the Sony app does. Initially the peripheral (a headphone) is not paired to the iPhone, as shown here:

enter image description here

I run the app and turn on the power of the headphone as instructed by the app:

enter image description here

After a while, the app finds and shows the headphone, and I tap it to register:

enter image description here

A dialog shows up and I tap again:

enter image description here

Finally the app reports that the headphone is registered.

enter image description here

Now in the Settings app I can see that the headphone is already paired and connected by the Sony app:

enter image description here

ycsun
  • 1,825
  • 1
  • 13
  • 21

1 Answers1

2

Pairing with MFi Devices:

You can import External Accessory framework and use showBluetoothAccessoryPicker to show Select An Accessory picker.

// Objective-C
[[EAAccessoryManager sharedAccessoryManager] showBluetoothAccessoryPickerWithNameFilter:nil completion:nil];

// Swift        
EAAccessoryManager.shared().showBluetoothAccessoryPicker(withNameFilter: nil, completion: nil)

Note: do not forget to add the protocols needs to be supported in Info.plist

Pairing with BLE Devices:

You can import Core Bluetooth framework and use scanForPeripherals from CBCentralManager to get the list of devices and create your custom picker to show it in didDiscover delegate method.

For more detailed steps on scanning and connecting with BLE devices, Refer here.

Prakash Shaiva
  • 1,047
  • 8
  • 12
  • Not that this feature is currently broken for most apps. It broke when Apple introduced the new Scene-based lifecycle. Roll back to the classic one and it starts working again. More details here: https://stackoverflow.com/a/70823487/415982 – DrMickeyLauer May 12 '22 at 14:00