Builds sensor workflows with Core Motion for accelerometer, gyroscope, device motion, pedometer, activity recognition, altitude, headphone motion, workout motion, and submersion/depth data. Use for motion interaction, steps, activity classification, AirPods tracking, or watchOS depth features.
84%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
Access accelerometer, gyroscope, attitude/device motion, pedometer, altitude, and specialized sensors using Core Motion. Targets Swift 6.4 / iOS 26+.
Add NSMotionUsageDescription to Info.plist explaining why the app accesses motion sensors.
Check authorization status for managers exposing privacy controls (CMPedometer, CMMotionActivityManager, CMAltimeter):
import CoreMotion
guard CMMotionActivityManager.authorizationStatus() != .denied else {
// Prompt user to enable motion permissions in Settings
return
}Raw accelerometer/gyro streams under CMMotionManager do not prompt for permission directly but require the usage description and throw errors on unauthorized access.
Maintain exactly one shared CMMotionManager instance per application to avoid sensor contention:
final class MotionProvider {
static let shared = MotionProvider()
let manager = CMMotionManager()
func startAccelerometer() {
guard manager.isAccelerometerAvailable else { return }
manager.accelerometerUpdateInterval = 1.0 / 60.0 // 60 Hz
manager.startAccelerometerUpdates(to: .main) { data, error in
guard let accel = data?.acceleration else { return }
// Process acceleration: x, y, z
}
}
func stop() {
manager.stopAccelerometerUpdates()
}
}Prefer CMDeviceMotion over raw sensor data. It fuses accelerometer, gyro, and magnetometer data into clean attitude, user acceleration, and gravity vectors:
manager.deviceMotionUpdateInterval = 1.0 / 60.0
manager.startDeviceMotionUpdates(using: .xArbitraryZVertical, to: .main) { motion, error in
guard let motion else { return }
let roll = motion.attitude.roll
let pitch = motion.attitude.pitch
let yaw = motion.attitude.yaw
}Track steps, distance, and user movement state:
let pedometer = CMPedometer()
if CMPedometer.isStepCountingAvailable() {
pedometer.startUpdates(from: .now) { data, error in
guard let data else { return }
print("Steps: \(data.numberOfSteps)")
}
}
let activityManager = CMMotionActivityManager()
if CMMotionActivityManager.isActivityAvailable() {
activityManager.startActivityUpdates(to: .main) { activity in
guard let activity else { return }
if activity.walking { print("Walking") }
if activity.running { print("Running") }
}
}startRelativeAltitudeUpdates).stopDeviceMotionUpdates()) when views disappear or when the app transitions to the background.CMDeviceMotion.attitude instead.isAvailable flags before calling startUpdates.NSMotionUsageDescription present and descriptive in Info.plistCMMotionManager instance used app-wideCMDeviceMotion used for orientation and tilt calculations instead of raw accelerometerthienqo/ios-skills
6bf8b62
Canonical home
since May 23, 2026
Also appears in
on Oct 29, 2026
since May 22, 2026
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.