pimlu
pimlu

Reputation: 87

Bluetooth connections on iOS

We're trying to observe when Bluetooth devices are connected and disconnected from an iPhone. We essentially want to react (not necessarily in the foreground) when certain devices of interest connect. In Android you can receive the ACL_CONNECTED and ACL_DISCONNECTED actions.

What is the equivalent to this behavior on iOS?

I first looked at CoreBluetooth before discovering it was for Bluetooth LE, then looked at ExternalAccessory, but it only shows MFI devices in the picker and seems to require users to go through the picker. The only method we found that would work would be to go through Apple's BluetoothManager itself, which is prohibited as per the AppStore guidelines in section 2.5, presumably so they can have total control over the Apple ecosystem.


Equivalent Android code:

MyReceiver.java

public class MyReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(BluetoothDevice.ACL_CONNECTED)) {
      //do stuff
    } else if (intent.getAction().equals(BluetoothDevice.ACL_DISCONNECTED)) {
      //do stuff
    }
  }

}

AndroidManifext.xml

<receiver
  android:name="com.myapp.MyReceiver"
  android:exported="true"
  android:enabled="true"
  android:label="MyReceiver">
  <intent-filters>
      <action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
      <action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
    </intent-filters>
</receiver>

Upvotes: 0

Views: 197

Answers (2)

Michael Dorner
Michael Dorner

Reputation: 20155

I published a demo app called Beetee which shows how Bluetooth classic is working on iOS and what the global events are. But this private framework is not AppStore complaint!

Upvotes: 1

MbientLab Inc
MbientLab Inc

Reputation: 71

You can't directly listen for global events like that in iOS, all apps are in their own sandbox and don't have access to each other.

That said, you could use the retrieveConnectedPeripheralsWithServices: method of the CBCentralManager to get a list of devices currently connected. Calling that function periodically and checking for changes could achieve what you are looking for.

Upvotes: 0

Related Questions