What's new in Nearby Interaction

Description: Discover how the Nearby Interaction framework can help you easily integrate Ultra Wideband (UWB) into your apps and hardware accessories. Learn how you can combine the visual-spatial power of ARKit with the radio sensitivity of the U1 chip to locate nearby stationary objects with precision. We’ll also show you how you can create background interactions using UWB accessories paired via Bluetooth.

Sample app

ARKit-enhanced Nearby Interaction

  • leverages the same underlying technology that powers Precision Finding with AirTag
  • available via Nearby Interaction
  • distance and direction information is more consistently available than using Nearby Interaction alone
  • best for use cases that need to guide a user to a specific nearby object
  • best used for interacting with stationary devices
  • Requires NSCameraUsageDescription purpose string in Info.plist

Enable this via the new NINearbyPeerConfiguration's isCameraAssistanceEnabled property

let session = NISession()

let configuration = NINearbyPeerConfiguration(..)
configuration.isCameraAssistanceEnabled = true // 👈🏻

session.run(configuration)

⚠️ Only a single ARSession can be running for a given application.

If you already have an ARKit experience in your app, it is necessary to share that ARSession with the NISession:

let niSession = NISession()

let arView = ARView(frame: .zero)
niSession.setARSesion(arView.session) // 👈🏻

Background sessions

Until now, when the app transitions to the background, or when the user locks the screen on iOS and watchOS, any running NISessions are suspended until the application returns to the foreground.

In iOS 16, we can connect to devices via BLE and then run a NISession in the background:

var niSession = NISession()

func runBackgroundSession(accessoryData: Data, peripheral: CBPeripheral) {
  // Provide the accessory's UWB configuration data, and its Bluetooth peer identifier
  let peerIdentifier = peripheral.identifier
  let config = NINearbyAccessoryConfiguration(
    accessoryData: accessoryData,
    bluetoothPeerIdentifier: peerIdentifier
  )
  session.run(config)
}

This helps create "hands-free" experiences, like having music start playing as soon as the user walks into a room.

This background mode requires the Nearby Interaction string in the UIBackgroundModes array in your app's Info.plist

Third-party hardware

  • U1-compatible development kits out of beta
  • Updated specification for accessory manufacturers

Check the developer portal for more details.

Missing anything? Corrections? Contributions are welcome 😃

Related

Written by

Federico Zanetello

Federico Zanetello

Software engineer with a strong passion for well-written code, thought-out composable architectures, automation, tests, and more.