Contents

PlaygroundBluetoothConnectionView.State

The states that tell users how to proceed when connecting to and switching between peripherals in a playground page.

Declaration

enum PlaygroundBluetoothConnectionView.State

Overview

The example below shows how to use the different states as part of adopting the PlaygroundBluetoothConnectionViewDelegate protocol.

extension PageViewDelegate: PlaygroundBluetoothConnectionViewDelegate {
    func connectionView(_ connectionView: PlaygroundBluetoothConnectionView, titleFor state: PlaygroundBluetoothConnectionView.State) -> String {
        // Pick a name that matches the types of peripheral your playground
        // supports, such as "Robot", "Speaker", or "Light".
        let name = "Peripheral"
        switch state {
        case .noConnection:
            return "Connect \(name)"
        case .connecting:
            return "Connecting \(name)"
        case .searchingForPeripherals:
            return "Searching for \(name)s"
        case .selectingPeripherals:
            return "Select a \(name)"
        case .connectedPeripheralFirmwareOutOfDate:
            return "Connect to a Different \(name)"
        }
    }
}

Topics

Waiting for Connections

Selecting Connections

Handling Old Firmware

Comparing Connection States

See Also

Handling State Changes