NINearbyAccessoryConfiguration
A configuration that enables interaction between iPhone and third-party accessories.
Declaration
class NINearbyAccessoryConfigurationMentioned in
Overview
Use this class to interact with a third-party accessory that you partner with or develop. The framework supports ranging with accessories using either Ultra Wideband (UWB) or Bluetooth Channel Sounding technology.
For an example app that demonstrates this configuration with UWB accessories, see Implementing spatial interactions with third-party accessories.
Discover the accessory and create a configuration
To begin the interaction, your app discovers the nearby accessory using a technology you choose — like Core Bluetooth, the local network, or a secure internet connection — and establishes a two-way data link.
For UWB accessories, over the data link, the accessory sends your app configuration data for the init(data:) initializer. The accessory formats the data according to the Ultra Wideband (UWB) third-party device specification.
For Bluetooth Channel Sounding accessories in iOS 27 and later, create a configuration using the init(bluetoothChannelSoundingIdentifier:previousBluetoothIdentifier:) initializer with the Bluetooth pairing identifier.
Enable background interaction for Bluetooth accessories
In iOS 16, third-party UWB accessories paired to the device through Bluetooth can interact with your app while it’s in the background. This enables a new class of hands-free experiences. For example, the person’s phone can be in their pocket and prompt an eBike to power on when mounted, or prompt lights to turn on and music to play as the person enters a room.
To enable background interaction:
The accessory implements the Bluetooth requirements described in the Ultra Wideband (UWB) third-party device specification.
The app connects and pairs to the accessory using Core Bluetooth.
The app calls the init(accessoryData:bluetoothPeerIdentifier:) initializer and passes in the accessory’s Bluetooth identifier.
Start a session and share configuration data
To start a session, the app creates an NISession instance and passes an instance of this class into the session’s run(_:) function. For UWB accessories, after your app sets the session delegate, the system invokes the delegate’s session(_:didGenerateShareableConfigurationData:for:) callback and provides your device’s configuration data.
Over the data link, your app sends your device’s configuration data to the UWB accessory, which enables the two devices to start receiving location updates. For Bluetooth Channel Sounding accessories, no configuration data exchange is necessary.
When the system gathers location updates for the accessory, Nearby Interaction calls your delegate’s session(_:didUpdate:) implementation. To match distance updates that your app receives through session(_:didUpdate:) with the accessory, compare the argument object’s discovery token with the value of this property’s accessoryDiscoveryToken.
Turn on Precision Finding for stationary objects
In iOS 16, you can combine the visual-spatial power of ARKit with the radio sensitivity of the Ultra Wideband (UWB) chips to locate stationary nearby objects with considerable precision. To do that, set isCameraAssistanceEnabled to true and optionally provide the interaction session with an ARSession instance through setARSession(_:) before running the session. Together, the UWB chip and ARKit’s assistance enable Nearby Interaction to provide the same Precision Finding capabilities present in AirTag.