Swift playgrounds provides full access to the PlaygroundBluetooth framework, which allows you to integrate bluetooth devices into your Playground Book. There are two main parts of the PlaygroundBluetooth framework.

• First is the PlaygroundBluetoothConnectionView, which allows you to customize a user interface that allows users to interact with devices.

• Second would be the PlaygroundBluetoothCentralManager, which is responsible for interacting with and managing devices.

The PlaygroundBluetoothCentralManagerDelegate has methods of interacting with devices, such as connecting to and disconnecting from devices. 

PlaygroundBluetoothCentralManagerDelegate

These are the methods you'll need for interface connectivity:

centralManagerStateDidChange(_: )

centralManager(_: didDiscover:withAdvertisementData: )

centralManager(_: willConnectTo: )

centralManager(_: didConnectTo: )

centralManager(_: didFailToConnect: error: )

centralManager(_: didDisconnectFrom: error: )

PlaygroundBluetooth is similar to CoreBluetooth’s CBCentralManager, so if you’ve implemented that before in a Bluetooth LE, then you reuse code here. Or you can take a look at the Create a Bluetooth LE app for iOS learn guide.

This guide was first published on Dec 22, 2017. It was last updated on Dec 22, 2017.

This page (Adding Bluetooth to your Playground Book) was last updated on Apr 18, 2021.

Text editor powered by tinymce.