How can i detect AirPods when they connect?

754 Views Asked by At

I would like to detect if my AirPods did connect. I was able to do it for any other bluetooth device, but cant find any observers to do the same for AirPods. Any ideas? tnx

1

There are 1 best solutions below

1
On

You can use the IOBluetooth framework. There’s a class called IOBluetoothDevice, which has a type method that allows you to register for device connect notifications.

IOBluetoothDevice.register(forConnectNotifications: self, selector: #selector(connectNotifications))

From here you can call isConnected on your IOBluetoothDevice instance and check if it’s connected or not.