
audioaccessorykit
Support automatic audio switching for paired third-party Bluetooth headphones or earbuds with AudioAccessoryKit. Use when a companion app registers an audio accessory, an app extension reports worn/removed placement or connected source-device changes, or AccessoryControlDevice capabilities and errors need handling. Do not use for general AVAudioSession routing, Bluetooth transport, or initial accessory pairing.
- Installs
- 3.1K
- Last 24h
- +15
- Trending rank
- #7097
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/dpearson2699/swift-ios-skills --skill audioaccessorykit- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads audioaccessorykit automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
AudioAccessoryKit
Automatic audio switching support and intelligent audio routing inputs for third-party audio accessories. Enables companion apps to register audio accessory configuration with the system, and app extensions to report placement and connected source changes that help the system switch audio output. Available iOS 26.4+ / iPadOS 26.4+.
Beta-sensitive. AudioAccessoryKit is new in iOS 26.4. Re-check current Apple documentation before relying on specific API details.
AudioAccessoryKit builds on top of AccessorySetupKit. The accessory must first
be paired via AccessorySetupKit before it can be registered for audio features.
The central type is AccessoryControlDevice, which registers a
Configuration from the container app and applies ongoing configuration updates
from the app extension.
Contents
- Setup
- Session Management
- Audio Switching
- Device Placement
- Connected Audio Sources
- Feature Discovery
- Error Handling
- Common Mistakes
- Review Checklist
- References
Setup
Prerequisites
- Pair the accessory over Bluetooth using AccessorySetupKit. This yields an
ASAccessoryobject. - Import the frameworks where needed in the container app and extension:
import AccessorySetupKit
import AudioAccessoryKit
Framework Availability
| Platform | Minimum Version |
|---|---|
| iOS | 26.4+ |
| iPadOS | 26.4+ |
In the current Xcode 26.6 toolchain, AudioAccessoryKit is present in the device
SDK but not the iPhone Simulator 26.5 SDK. Use a physical-device destination
for this target. If the rest of the app must build for Simulator, isolate target
membership or guard the import and implementation with
#if canImport(AudioAccessoryKit) and provide a simulator stub.
Session Management
Registering an Accessory
After pairing via AccessorySetupKit, register the accessory from the container
app by passing an AccessoryControlDevice.Configuration that describes the
capabilities and any initial state the accessory supports:
let accessory: ASAccessory // Obtained from AccessorySetupKit pairing
let configuration = AccessoryControlDevice.Configuration(
devicePlacement: .offHead,
deviceCapabilities: [.audioSwitching, .placement]
)
try await AccessoryControlDevice.register(accessory, configuration)
Registration activates the specified capabilities and gives the system the configuration it needs to participate in audio routing decisions.
Retrieving the Current Configuration
In the app extension, access the device's current configuration using the
static current(for:) method:
let device = try AccessoryControlDevice.current(for: accessory)
let currentConfig = device.configuration
This returns the AccessoryControlDevice instance associated with the paired
ASAccessory. The device exposes both the accessory reference and the
current configuration. Apple marks current(for:) as app-extension-only.
Updating Configuration
In the app extension, push configuration changes to the system with
update(_:). Only update fields for capabilities that were declared during
registration:
let device = try AccessoryControlDevice.current(for: accessory)
var config = device.configuration
config.devicePlacement = .onHead
try await device.update(config)
Treat this as a gated write workflow: confirm registration declared the
capability, copy and mutate device.configuration, then try await update(_:).
The method returns no configuration value; update an app-side mirror only after
the call succeeds. On failure, use the disposition in
Error Handling. Apple marks update(_:) as
app-extension-only.
Audio Switching
Automatic audio switching lets the system intelligently route audio output to the correct device based on placement and connected sources.
Enabling Audio Switching
Declare .audioSwitching during the canonical registration flow above. Include
.placement and an initial placement only when the accessory can report ongoing
placement changes.
Capabilities
Automatic switching commonly uses these AccessoryControlDevice.Capabilities:
| Capability | Purpose |
|---|---|
.audioSwitching | Device supports automatic audio switching |
.placement | Device can report its physical placement |
Combine capabilities as needed. Do not declare .placement unless the
accessory can keep the system updated with real placement state.
Device Placement
Report the physical position of the accessory from the app extension to help the system make routing decisions. Update placement whenever the accessory detects a position change.
Placement Values
AccessoryControlDevice.Placement defines four cases:
| Placement | Meaning |
|---|---|
.inEar | Accessory is seated in the ear (e.g., earbuds) |
.onHead | Accessory is on the head (e.g., headband headphones) |
.overTheEar | Accessory is over the ear (e.g., over-ear headphones) |
.offHead | Accessory is not being worn |
Updating Placement
config.devicePlacement = .inEar
Apply this mutation within the canonical current→copy→update sequence above.
Common transitions:
.offHeadto.onHeador.inEarwhen the user puts on the accessory.onHeador.inEarto.offHeadwhen removed- Update promptly on every detected change for responsive audio routing
Connected Audio Sources
For accessories that connect to multiple Bluetooth devices simultaneously, inform the system from the app extension which devices are connected. This lets the system route audio from the appropriate source.
Setting Audio Source Identifiers
Provide the Bluetooth address of connected devices as Data:
let primaryBTAddress = Data([0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC])
config.primaryAudioSourceDeviceIdentifier = primaryBTAddress
let secondaryBTAddress = Data([0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45])
config.secondaryAudioSourceDeviceIdentifier = secondaryBTAddress
Update these identifiers when the Bluetooth connection state changes (new
device connects, existing device disconnects), then call the canonical
update(_:) sequence.
Configuration Properties
Automatic switching uses these configuration fields:
| Property | Type | Purpose |
|---|---|---|
deviceCapabilities | Capabilities | Declared device capabilities |
devicePlacement | Placement? | Current physical placement |
primaryAudioSourceDeviceIdentifier | Data? | Primary connected Bluetooth device address |
secondaryAudioSourceDeviceIdentifier | Data? | Secondary connected Bluetooth device address |
Feature Discovery
Querying Capabilities
In the app extension, inspect the device's declared capabilities through its configuration:
let device = try AccessoryControlDevice.current(for: accessory)
let caps = device.configuration.deviceCapabilities
if caps.contains(.audioSwitching) {
// Device supports automatic audio switching
}
if caps.contains(.placement) {
// Device reports physical placement
}
Checking Placement
Read the current placement to determine if the accessory is being worn:
let device = try AccessoryControlDevice.current(for: accessory)
if let placement = device.configuration.devicePlacement {
switch placement {
case .inEar, .onHead, .overTheEar:
// Accessory is being worn
break
case .offHead:
// Accessory is not being worn
break
@unknown default:
break
}
}
Error Handling
AccessoryControlDevice.Error covers failure cases during registration and
updates:
| Error | Cause |
|---|---|
.accessoryNotCapable | Accessory does not support the requested capability |
.invalidRequest | Request parameters are invalid |
.invalidated | Device registration has been invalidated |
.unknown | An unspecified error occurred |
Handle errors from registration and update calls:
let configuration = AccessoryControlDevice.Configuration(
devicePlacement: .offHead,
deviceCapabilities: [.audioSwitching, .placement]
)
do {
try await AccessoryControlDevice.register(accessory, configuration)
} catch let error as AccessoryControlDevice.Error {
switch error {
case .accessoryNotCapable:
// Accessory hardware does not support requested capabilities
break
case .invalidRequest:
// Check registration parameters
break
case .invalidated:
// Coordinate container-app registration again
break
case .unknown:
// Log, surface, or propagate; Apple does not classify this as transient
throw error
@unknown default:
throw error
}
}
Do not infer that .invalidated or .unknown is transient. Correct invalid
capabilities or request parameters, discard an invalidated handle and notify
the container app to re-evaluate registration where appropriate, and surface unspecified errors. Load
Error Recovery Patterns
for the complete disposition and invalidation handoff.
Common Mistakes
DON'T: Register before pairing with AccessorySetupKit
Register only the ASAccessory returned by a completed AccessorySetupKit pairing.
DON'T: Declare placement capability without updating placement
If registration declares .placement, the extension must update placement on
every detected transition using the canonical update sequence.
DON'T: Ignore connection state changes for multi-device accessories
Clear or replace primary and secondary source identifiers whenever Bluetooth connections change; stale identifiers reduce switching accuracy.
DON'T: Forget to handle the invalidated error
// WRONG -- ignores invalidation, keeps using stale device reference
try await device.update(config) // Throws .invalidated, unhandled
// CORRECT -- discard the handle and let the container re-evaluate registration
do {
try await device.update(config)
} catch AccessoryControlDevice.Error.invalidated {
await notifyContainerAppToReevaluateRegistration(accessory)
}
Review Checklist
- Accessory paired via AccessorySetupKit before AudioAccessoryKit registration
- Both
AccessorySetupKitandAudioAccessoryKitimported - Container app calls
register(_: _:)withAccessoryControlDevice.Configuration - App extension calls
current(for:)andupdate(_:) - Capabilities in the registration configuration match actual hardware support
- Updates only touch fields for capabilities declared during registration
-
.placementcapability accompanied by ongoing placement updates - Placement transitions (on/off head) reported promptly
- Audio source device identifiers updated on Bluetooth connection changes
- All
AccessoryControlDevice.Errorcases handled, including@unknown default -
update(_:)calls usetry awaitand handle errors - Invalidated device references trigger container-app registration recovery
- Deployment target set to iOS 26.4+ or iPadOS 26.4+
References
- Extended patterns (registration flow, placement monitoring, multi-device coordination): references/audioaccessorykit-patterns.md
- AudioAccessoryKit framework
- Supporting automatic audio switching
- AccessoryControlDevice
- AccessoryControlDevice registration
- AccessoryControlDevice lookup
- AccessoryControlDevice update
- AccessoryControlDevice.Configuration
- AccessoryControlDevice.Capabilities
- AccessoryControlDevice.Placement
- AccessorySetupKit framework (prerequisite for pairing)
FAQ
What does the audioaccessorykit skill do?
Support automatic audio switching for paired third-party Bluetooth headphones or earbuds with AudioAccessoryKit. Use when a companion app registers an audio accessory, an app extension reports worn/removed placement or connected source-device changes, or AccessoryControlDevice capabilities and errors need handling. Do not use for general AVAudioSession routing, Bluetooth transport, or initial accessory pairing.
How do I install audioaccessorykit?
Run npx skills add https://github.com/dpearson2699/swift-ios-skills --skill audioaccessorykit in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/audioaccessorykit/ (personal) or .claude/skills/audioaccessorykit/ (project).
Which AI agents can use audioaccessorykit?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is audioaccessorykit safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains audioaccessorykit?
It is published by dpearson2699 in dpearson2699/swift-ios-skills. It has 3,062 recorded installs.
More from dpearson2699/swift-ios-skills
swiftui-animation
dpearson2699/swift-ios-skills
Implement, diagnose, or review SwiftUI motion using explicit and scoped implicit animations, springs, transitions, PhaseAnimator, KeyframeAnimator, matched geometry or navigation zoom, SF Symbol effects, and custom Animation types. Use when views should animate on state changes, insertion, removal, navigation, or multi-step choreography, or when motion must respect Reduce Motion and Swift concurrency.
ios-accessibility
dpearson2699/swift-ios-skills
Build and audit SwiftUI, UIKit, and AppKit accessibility for VoiceOver, Voice Control, Switch Control, Full Keyboard Access, Dynamic Type, focus restoration, labels/traits/actions, traversal, custom rotors, NSAccessibility, XCTest checks, adaptive system preferences, and App Store accessibility declarations. Use when implementing accessible UI, fixing an accessibility audit, testing assistive-technology behavior, or substantiating App Store Accessibility Nutrition Labels.
swiftui-performance
dpearson2699/swift-ios-skills
Profile, diagnose, and remediate SwiftUI runtime performance using code review, Instruments, and repeatable measurements. Use when a SwiftUI screen renders slowly, scrolling or animations hitch, view bodies update excessively, list identity churns, layout work spikes, or broad Observation dependencies raise CPU cost. Covers evidence-based triage, SwiftUI Instruments lanes, lazy-container guardrails, state lifetime, and before/after verification.
swiftui-patterns
dpearson2699/swift-ios-skills
Builds and reviews SwiftUI views with modern MV architecture, state, composition, isolated previews, and migration guidance. Covers @Observable ownership, @State/@Bindable/@Environment wiring, view decomposition, ViewModifiers, environment values, .task loading, iOS 26+ handoffs, Writing Tools, clipboard availability, and performance. Use when structuring SwiftUI state, managing @Observable, composing views, previewing meaningful UI states, or correcting SwiftUI patterns.
app-store-review
dpearson2699/swift-ios-skills
Audits App Store submission readiness and rejection risk across current review guidelines, PrivacyInfo.xcprivacy and required-reason APIs, privacy labels, ATT, StoreKit payments, metadata, entitlements, widgets, and Live Activities. Use when preparing a submission, responding to rejection, reconciling privacy evidence, or separating upload blockers from cleanup.
ios-networking
dpearson2699/swift-ios-skills
Build, review, or improve networking code in iOS/macOS apps using URLSession with async/await, structured concurrency, and modern Swift patterns. Use when working with REST APIs, downloading files, uploading data, WebSocket connections, pagination, retry logic, request middleware, caching, background transfers, or network reachability monitoring. Also use when handling HTTP requests, API clients, network error handling, or data fetching in Swift apps.
Popular mobile skills
design-mobile-apps
designed-by-ai/skills
Design mobile app screens with Sleek, edit Sleek projects, and implement their designs in React Native or HTML.
ios-design
uizze.sh
Design and review iOS UI/UX for iPhone apps in SwiftUI, UIKit, or React Native. Use for mobile app design, screen redesigns, navigation flows, typography, forms, keyboard and safe-area layout, and accessibility checks. Apply Apple Human Interface Guidelines and consult real product references through the optional Uizze connection.
vercel-react-native-skills
vercel-labs/agent-skills
React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.
animate-expo
emilkowalski/skills
Build animations in React Native and Expo, making the decisions in the order that determines whether they feel right — should it animate, which thread it runs on, which properties, spring or timing, how the gesture hands off, how it degrades. Writes the implementation with Reanimated, Gesture Handler, Expo Router and expo-haptics. Use when animating anything in an Expo app, adding gestures, sheets, screen transitions, press feedback or haptics, or fixing motion that stutters on device. For web animation use animate.
xcode-project-setup
firebase/agent-skills
Safely modifies Xcode projects (.pbxproj) to add Swift Packages and link files. Use this skill whenever an iOS project needs dependencies installed (e.g. Firebase, Alamofire).
firebase-remote-config-basics
firebase/agent-skills
Manages Firebase Remote Config templates, feature flags, loading strategies, and SDKs (Android, iOS). Use when downloading/deploying remoteconfig JSON templates, managing version history/feature flags, setting in-app defaults, fetchAndActivate(), real-time listeners, or SDK setup. Don't use for Firebase Hosting, Auth, Firestore, Data Connect, Crashlytics, or App Hosting.