Measure Accessory Distance With Bluetooth Channel Sounding
A room contains three identical Bluetooth accessories. Their names tell you what they are, but not which one is beside you. A distance-aware screen could make that interaction much less frustrating.
WWDC26 introduced Bluetooth Channel Sounding on iOS. Core Bluetooth provides distance measurements; Nearby Interaction can add direction with camera assistance. For a first implementation, a distance-only feature has a useful, testable scope.
Check both ends of the connection
Apple describes support on iPhones with the N1 chip, but a device-name list should not drive the UI. Query the runtime feature after Bluetooth is powered on. The accessory also needs the supported Channel Sounding implementation; a generic “Bluetooth 6” label is insufficient.
The WWDC session specifies Bluetooth 6.3, inline PCT, phase-based ranging modes 0 and 2, and the required interspace timing support. Confirm those requirements with the accessory’s firmware/chipset team before spending a week debugging the app layer.
Use Apple’s sample and setup guidance for pairing and connection. The following adapter assumes that work is already complete and that the app owns a connected peripheral.
Keep the transport adapter small
The installed iOS 27 SDK imports the feature check as CBCentralManager.supports and the measurement callback as peripheral(_:didReceive:error:). Here is a type-checked distance adapter:
import CoreBluetooth
@available(iOS 27.0, *)
func beginRanging(_ peripheral: CBPeripheral, central: CBCentralManager) -> Bool {
guard central.state == .poweredOn,
peripheral.state == .connected,
CBCentralManager.supports(.channelSounding)
else { return false }
let configuration = CBChannelSoundingSessionConfiguration(role: .initiator)
peripheral.startChannelSoundingSession(configuration)
return true
}
@available(iOS 27.0, *)
final class RangingDelegate: NSObject, CBPeripheralDelegate {
let measurement: @Sendable (UUID, Double?) -> Void
let ended: @Sendable (UUID, Bool) -> Void
init(
measurement: @escaping @Sendable (UUID, Double?) -> Void,
ended: @escaping @Sendable (UUID, Bool) -> Void
) {
self.measurement = measurement
self.ended = ended
}
func peripheral(
_ peripheral: CBPeripheral,
didReceive results: CBChannelSoundingProcedureResults?,
error: (any Error)?
) {
guard error == nil, let meters = results?.distance,
meters.isFinite, meters >= 0
else {
measurement(peripheral.identifier, nil)
return
}
measurement(peripheral.identifier, meters)
}
func peripheral(
_ peripheral: CBPeripheral,
didCompleteChannelSoundingSession error: (any Error)?
) {
ended(peripheral.identifier, error != nil)
}
}
@available(iOS 27.0, *)
func stopRanging(_ peripheral: CBPeripheral) {
peripheral.cancelChannelSoundingSession()
}
beginRanging returning true means the request was submitted, not that a distance is already available. Keep the UI in a searching state until a usable measurement arrives.
The adapter rejects missing, negative, and nonfinite measurements. It forwards the peripheral ID with each value so the presentation layer cannot accidentally show one accessory’s distance beside another accessory’s name.
The callbacks deliberately carry small values rather than Core Bluetooth objects. Dispatch those values to your UI’s isolation domain. Keep all peripheral/session decisions on the queue already used by your Bluetooth owner.
Integrate these methods into that owner’s existing peripheral delegate, or retain and install this delegate where it is the sole owner. Do not replace a delegate that another feature uses for service discovery or characteristic updates. The adapter is not a second Bluetooth connection manager.
Model searching, measuring, and stale separately
A failed procedure does not prove the accessory is far away. The sample sends nil for an unusable reading so the UI can show “Measuring…” or retain a clearly marked last-known value. It must not turn nil into zero meters.
Associate each accepted reading with a monotonic receipt time. After a product-defined freshness interval, stop presenting it as current. Choose that interval from device testing: iOS can reduce measurement frequency during competing radio activity, so an aggressively short threshold may flicker between valid and stale constantly.
Keep formatting independent from measurement. Store meters as a numeric value, format for the user’s measurement preferences, and round to a precision the real experience supports. A long decimal string suggests confidence the app has not established.
Test a sequence with a valid reading, an error, a pause, and another valid reading. Include an accessory switch while UI updates are queued. The currently selected accessory and session generation should decide which events may update the screen.
Own the session through its end
Start once for a user-visible ranging interaction. Cancel when that interaction ends, and observe the completion callback before restarting the same peripheral’s session. An explicit starting/running/stopping state prevents repeated button taps from creating ambiguous requests.
In iOS 27, Apple describes Channel Sounding as a foreground feature; it pauses when the app backgrounds. Treat that transition as a presentation-state change. A frozen last distance should not look like a live sensor while the app is inactive.
The example’s completion callback reports whether the session ended with an error. A production owner should preserve the underlying error category for diagnostics and recovery, while showing a useful user-facing state. Do not turn every procedure error into an immediate reconnect loop.
Add direction only when the experience needs it
A distance label can answer “which accessory is close?” It cannot draw a truthful pointing arrow. Apple’s Nearby Interaction path requires camera assistance for direction, and its distance/direction values can be absent.
If the feature needs directional guidance, prototype that path with the real accessory and permission flow. Keep a distance-only or unavailable state for situations where the requested guidance cannot be produced. Never manufacture direction from the distance trend alone.
September 2026 verification: the Core Bluetooth adapter and delegate selector type-check in Swift 6 mode against Xcode 27.0’s iOS 27 SDK. No compatible reflector accessory was available for this work, so measurement accuracy, radio contention, foreground transitions, and firmware interoperability remain hardware-validation tasks.
The interesting part of Channel Sounding is the interaction it enables. A small, honest distance feature with clear ownership is more useful than a precise-looking number that belongs to the wrong accessory or stopped updating several seconds ago.