dockkit
Control motorized camera docks and enable intelligent subject tracking using DockKit. Use when discovering DockKit-compatible accessories, implementing camera subject tracking for faces or bodies, controlling dock motors for pan and tilt, configuring framing behavior, setting regions of interest, or
By dpearson2699 · 2,616 installs
npx skills add dpearson2699/swift-ios-skills --skill dockkit
Source repository · Upstream listing
DockKit
Framework for integrating with motorized camera stands and gimbals that
physically track subjects by rotating the iPhone. DockKit handles motor
control, subject detection, and framing so camera apps get 360 degree pan
and 90 degree tilt tracking with no additional code. Apps can override
system tracking to supply custom observations, control motors directly,
or adjust framing. iOS 17+, Swift 6.3.
Contents
[Setup]( setup)
[Discovering Accessories]( discovering accessories)
[System Tracking]( system tracking)
[Custom Tracking]( custom tracking)
[Framing and Region of Interest]( framing and region of interest)
[Motor Control]( motor control)
[Animations]( animations)
[Tracking State and Subject Selection]( tracking state and subject selection)
[Accessory Events]( accessory events)
[Battery Monitoring]( battery monitoring)
[Common Mistakes]( common mistakes)
[Review Checklist]( review checklist)
[References]( references)
Setup
Import DockKit:
DockKit requires a physical DockKit compatible accessory and a real device.
The Simulator cannot connect to dock hardware.
DockKit itself requires no special entitlements or DockKit specific
Info.plist keys. Camera apps that use device cameras still need normal
camera privacy handling, including NSCameraUsageDescription . The framework
communicates with paired accessories automatically through the DockKit
system daemon.
The app must use AVFoundation camera APIs. DockKit hooks into the camera
pipeline to analyze frames for system tracking.
Discovering Accessories
Use DockAccessoryManager.shared to observe dock connections:
accessoryStateChanges emits DockAccessory.StateChange values with state ,
accessory , and trackingButtonEnabled . Use accessory.identifier for the
name, category, and UUID; hardware details are available via firmwareVersion
and hardwareModel .
System Tracking
System tracking is DockKit's default mode. When enabled, the system
analyzes camera frames through built in ML inference, detects faces and
bodies, and drives the motors to keep subjects in frame. Any app using
AVFoundation camera APIs benefits automatically.
Enable or Disable
System tracking state does not persist across app termination, reboots,
or background/foreground transitions. Set it explicitly whenever the app
needs a specific value.
Tap to Select Subject
Allow users to select a specific subject by tapping:
Custom Tracking
Disable system tracking and provide your own observations when using
custom ML models or the Vision framework.
Providing Observations
Construct DockAccessory.Observation values from your inference output
and pass them to the accessory at 10 30 fps:
Observation Types
When reviewing custom tracking, explicitly choose among the only supported
ObservationType cases: .humanFace , .humanBody , and .object .
Do not answer with only .humanFace when body or object detections are possible.
The rect uses normalized coordinates with a lower left origin (same
coordinate system as Vision framework no conversion needed).
Camera Information
DockAccessory.CameraInformation describes the active camera; do not hardcode
placeholder device, intrinsics, or frame size values. Set orientation to
.corrected when coordinates are already relative to the bottom left corner.
In review answers, reject opaque optional cameraInfo placeholders and show
construction from the active AVCaptureDevice plus the current CMSampleBuffer .
Track variants also accept [AVMetadataObject] instead of observations.
Use the image: CVPixelBuffer overloads when DockKit should combine
observations or metadata with the captured image buffer; the image argument
is required in those overloads.
Framing and Region of Interest
Framing Modes
Control how the system frames tracked subjects:
Mode Behavior
.automatic Documented default; system decides optimal framing
.center Explicit opt in mode to keep subject centered
.left Frame subject in left third
.right Frame subject in right third
Default system behavior often centers the primary subject, but .center is
never the default like mode; .automatic is. Use .left or .right when
graphic overlays occupy part of the frame.
Region of Interest
Constrain tracking to a specific area of the video frame:
Use region of interest when cropping to a non standard aspect ratio
(e.g., square video for conferencing) so subjects stay within the
visible area.
Motor Control
Disable system tracking before controlling motors directly.
Angular Velocity
Set continuous rotation speed in radians per second:
Axes:
x pitch (tilt). Positive tilts down on iOS.
y yaw (pan). Positive pans right.
z roll (if supported by hardware).
Set Orientation
Move to a specific position over a duration:
Also accepts Rotation3D for quaternion based orientation. Set
relative: true to move relative to the current position. The returned
Progress object tracks completion.
Motion State
Monitor the accessory's current position and velocity:
Setting Limits
Restrict range of motion and maximum speed per axis:
Animations
Built in character animations that move the dock expressively:
Animation Effect
.yes Nodding motion
.no Shaking motion
.wakeup Startup style motion
.kapow Dramatic pendulum swing
Animations start from the accessory's current position and execute
asynchronously. Always restore tracking state after completion. Keep
animate(motion:) and setOrientation( :duration:relative:) calls to no
more than twice per second; higher call rates can throw .frameRateTooHigh .
Tracking State and Subject Selection
iOS 18+ exposes ML derived tracking signals through the throwing
trackingStates async sequence. Each state has time and trackedSubjects
( .person or .object ); persons include identifier , rect ,
speakingConfidence , lookingAtCameraConfidence , and saliencyRank
(lower rank is more salient).
Use selectSubjects( :) to lock tracking by UUID; pass [] to return to
automatic selection. Use speakingConfidence for speakers,
lookingAtCameraConfidence for engagement, rect for overlays, and lower
saliencyRank values as fallback.
In review answers, consume lookingAtCameraConfidence and rect in code, not
just prose.
Accessory Events
Physical buttons on the dock trigger events through the throwing
accessoryEvents async sequence (iOS 17.4+):
Third party apps receive these events and implement behavior through
AVFoundation.
Battery Monitoring
Monitor the dock's battery status through the throwing batteryStates async
sequence (iOS 18+). A dock can report multiple batteries, each identified by
name :
Common Mistakes
DON'T: Control motors without disabling system tracking
DON'T: Assume tracking state persists across lifecycle events
DON'T: Call track() outside the recommended rate
DON'T: Spam orientation or animation calls
DockKit can throw .frameRateTooHigh if animate(motion:) or
setOrientation( :duration:relative:) is called more than twice per second.
Set a trajectory, observe its Progress , and avoid tight command loops.
DON'T: Forget to restore tracking after animations
DON'T: Use DockKit in Simulator
DockKit requires a physical DockKit compatible accessory. Guard
initialization and provide fallback behavior when no accessory is
available.
Review Checklist
[ ] import DockKit present where needed
[ ] Subscribed to accessoryStateChanges to detect dock/undock events
[ ] Handled both .docked and .undocked states
[ ] System tracking disabled before custom tracking or motor control
[ ] System tracking restored after animations complete
[ ] Custom observations supplied at 10 30 fps
[ ] animate and setOrientation commands limited to 2 calls per second
[ ] Observation rect uses normalized coordinates (lower left origin)
[ ] Camera information is built inline from the active AVCaptureDevice and current sample buffer
[ ] Observation type choice names .humanFace , .humanBody , and .object
[ ] @unknown default handled in all switch statements over DockKit enums
[ ] Motion limits set if restricting accessory range of motion
[ ] Tracking state re applied after app returns to foreground
[ ] accessoryEvents guarded with available(iOS 17.4, )
[ ] trackingStates and batteryStates guarded with available(iOS 18.0, )
[ ] Battery UI preserves BatteryState.name for multi battery docks
[ ] No DockKit code paths executed in Simulator builds
References
Extended patterns (Vision integration, service architecture, custom animations): [references/dockkit patterns.md](references/dockkit patterns.md)
[DockKit framework](https://sosumi.ai/documentation/dockkit)
[DockAccessoryManager](https://sosumi.ai/documentation/dockkit/dockaccessorymanager)
[DockAccessory](https://sosumi.ai/documentation/dockkit/dockaccessory)
[Controlling a DockKit accessory using your camera app](https://sosumi.ai/documentation/dockkit/controlling a dockkit accessory using your camera app)
[Track custom objects in a frame](https://sosumi.ai/documentation/dockkit/track custom objects in a frame)
[Modify rotation and positioning programmatically](https://sosumi.ai/documentation/dockkit/modify rotation and positioning behavior programmatically)
[Integrate with motorized iPhone stands using DockKit WWDC23](https://sosumi.ai/videos/play/wwdc2023/10304/)
[What's new in DockKit WWDC24](https://sosumi.ai/videos/play/wwdc2024/10164/)