HeadphoneMotionManager PRO
The HeadphoneMotionManager namespace streams motion data from headphones that support spatial audio with dynamic head tracking, such as AirPods Pro, AirPods Max, and AirPods 3.
It wraps Apple's CMHeadphoneMotionManager and exposes attitude, rotation rate, user acceleration, gravity, and connection events to your scripts.
Properties
Authorization is handled internally — your script does not need to query or request permission. The first call to
startDeviceMotionUpdatestriggers the system prompt automatically; if the user later denies access, subsequent calls reject with a clear error.
Methods
startDeviceMotionUpdates(options): Promise<boolean>
Begin streaming motion samples. Resolves with true once the stream is started.
Only one active subscription is supported at a time. Calling startDeviceMotionUpdates again replaces the previous handler.
stopDeviceMotionUpdates(): void
Stop the current motion stream. Safe to call when no stream is active.
addListener(event, listener): void
Subscribe to a connection event.
connectfires when supported headphones become reachable.disconnectfires when they go away.
removeListener(event, listener): void
Remove a previously registered listener. Pass the same function reference that was used with addListener.
Data Types
Example
Notes
Info.plistmust includeNSMotionUsageDescription. Scripting already declares it.- The first call to
startDeviceMotionUpdatesautomatically triggers the system Motion & Fitness permission prompt. If the user denies it (now or later from Settings),startDeviceMotionUpdatesrejects with a clear error so your script can surface a helpful message.
