init(bluetoothChannelSoundingIdentifier:previousBluetoothIdentifier:)
Initializes a configuration for Bluetooth Channel Sounding ranging with an accessory.
Declaration
init(bluetoothChannelSoundingIdentifier bluetoothIdentifier: UUID, previousBluetoothIdentifier: UUID?)Parameters
- previousBluetoothIdentifier:
An optional previous Bluetooth identifier for reconnection scenarios.
Discussion
Bluetooth Channel Sounding is a Bluetooth 6.0 specification ranging strategy that measure distance between iPhone and a paired accessory over a standard Bluetooth connection without requiring dedicated Ultra Wideband hardware.
Use this initializer to create an accessory configuration that implements Bluetooth Channel Sounding. Call supportsBluetoothChannelSounding before running a session to ensure device support, and pair your accessory with AccessorySetupKit; the Nearby Interaction framework only supports Bluetooth Channel Sounding with accessories paired through AccessorySetupKit.
Handle reconnections
When reconnecting to an accessory where the Bluetooth identifier can change, provide the previous identifier using the previousBluetoothIdentifier parameter. This allows the session to maintain internal state continuity across reconnections. For initial connections, pass nil for this parameter.
// Initial connection.
let config = NINearbyAccessoryConfiguration(
bluetoothChannelSoundingIdentifier: btcsIdentifier,
previousBluetoothIdentifier: nil
)
session.run(config)
// Reconnection with a new identifier.
let reconnectConfig = NINearbyAccessoryConfiguration(
bluetoothChannelSoundingIdentifier: newBtcsIdentifier,
previousBluetoothIdentifier: previousBtcsIdentifier
)
session.run(reconnectConfig)