<!--
{
  "documentType" : "article",
  "framework" : "AudioAccessoryKit",
  "identifier" : "/documentation/AudioAccessoryKit/supporting-automatic-audio-switching",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Supporting automatic audio switching for third-party accessories"
}
-->

# Supporting automatic audio switching for third-party accessories

Configure your audio accessory to support seamless audio routing between connected devices.

## Overview

AudioAccessoryKit lets you provide information to the system to support audio switching. The device’s companion app starts by pairing the device over Bluetooth using AccessorySetupKit.  After successfully pairing, register the device with AudioAccessoryKit, providing a list of the audio accessory device’s capabilities to the system.  For example, during registration, the companion app tells the system whether the device can report its physical placement and whether it supports automatic audio switching.  While someone uses the device, the companion app updates the system about changes to the device, such as when someone puts on a pair of headphones.

## Pair and register your accessory

Before configuring audio features, pair your accessory using <doc://com.apple.documentation/documentation/AccessorySetupKit>. After pairing completes successfully, you receive an <doc://com.apple.documentation/documentation/AccessorySetupKit/ASAccessory> object from the system that represents your paired device.  You use that object in your container app to register the device with AudioAccessoryKit.

After pairing your accessory with the system, create an [`AccessoryControlDevice`](/documentation/AudioAccessoryKit/AccessoryControlDevice) for your accessory and the capabilities it supports. For automatic audio switching, specify the [`audioSwitching`](/documentation/AudioAccessoryKit/AccessoryControlDevice/Capabilities/audioSwitching) and [`placement`](/documentation/AudioAccessoryKit/AccessoryControlDevice/Capabilities/placement) capabilities, as demonstrated below:

```swift
let accessory: ASAccessory  // The object from pairing your accessory.
let capabilities: AccessoryControlDevice.Capabilities = [.audioSwitching, .placement]
try await AccessoryControlDevice.register(accessory, capabilities)
```

When you register the device, it activates the specified capabilities and the system begins routing audio to your accessory.

## Update device placement

Communicate the current placement of your accessory to support intelligent audio routing by setting  [`devicePlacement`](/documentation/AudioAccessoryKit/AccessoryControlDevice/Configuration-swift.struct/devicePlacement) from your app extension. Update the placement when your accessory detects a change in its position.

```swift
let device = AccessoryControlDevice.current(for: accessory)
var configuration = device.configuration

configuration.devicePlacement = .inEar
try await device.update(configuration)
```

Common placement transitions include moving from [`AccessoryControlDevice.Placement.offHead`](/documentation/AudioAccessoryKit/AccessoryControlDevice/Placement/offHead) to [`AccessoryControlDevice.Placement.onHead`](/documentation/AudioAccessoryKit/AccessoryControlDevice/Placement/onHead) or [`AccessoryControlDevice.Placement.inEar`](/documentation/AudioAccessoryKit/AccessoryControlDevice/Placement/inEar) when the someone puts on the accessory, and back to [`AccessoryControlDevice.Placement.offHead`](/documentation/AudioAccessoryKit/AccessoryControlDevice/Placement/offHead) when removed.  Continue to provide updates to the system, any time the accessory someone places the accessory in a different position.

## Provide connected audio source devices

For accessories that connect to multiple Bluetooth devices, inform the system from your app extensions of which devices are connected by setting the devices’ Bluetooth addresses as the primary or secondary audio device.  Providing this information lets the system route audio from the appropriate source.

```swift
let device = AccessoryControlDevice.current(for: accessory)
var configuration = device.configuration

let bluetoothID = Data([0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC]
configuration.primaryAudioSourceDeviceIdentifier = bluetoothID
try await device.update(configuration)
```

Update the connected devices when your accessory’s Bluetooth connection state changes, such as when a new device connects or an existing device disconnects.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)