# Core Motion

Access Core Motion accelerometer, gyroscope, magnetometer, device-motion, pedometer...

- Repository: https://github.com/dpearson2699/swift-ios-skills (1266 stars)
- Category: Engineering
- License: see repository
- Last updated: 2026-07-31
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add dpearson2699/swift-ios-skills --skill core-motion -g -a claude-code -y`
Codex: `npx skills add dpearson2699/swift-ios-skills --skill core-motion -g -a codex -y`
Cursor: `npx skills add dpearson2699/swift-ios-skills --skill core-motion -g -a cursor -y`
Gemini CLI: `npx skills add dpearson2699/swift-ios-skills --skill core-motion -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add dpearson2699/swift-ios-skills`

## Description

Access Core Motion accelerometer, gyroscope, magnetometer, device-motion, pedometer, activity-recognition, altitude, headphone motion, batched high-frequency workout motion, and water-submersion/depth data. Use when reading device sensors, counting steps, detecting walking/running/driving/cycling, tracking altitude, building motion interactions, handling AirPods head tracking, or implementing watchOS dive/depth features.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# CoreMotion

Read device motion, pedometer/activity, altitude, headphone, batched-workout,
and submersion sensors with Core Motion. Scope: Swift 6.3, iOS 26+.

## Contents

- [Setup](#setup)
- [CMMotionManager: Sensor Data](#cmmotionmanager-sensor-data)
- [Processed Device Motion](#processed-device-motion)
- [CMPedometer: Step and Distance Data](#cmpedometer-step-and-distance-data)
- [CMMotionActivityManager: Activity Recognition](#cmmotionactivitymanager-activity-recognition)
- [CMAltimeter: Altitude Data](#cmaltimeter-altitude-data)
- [Update Intervals and Battery](#update-intervals-and-battery)
- [Common Mistakes](#common-mistakes)
- [Review Checklist](#review-checklist)
- [References](#references)

## Setup

### Info.plist

Add `NSMotionUsageDescription` to Info.plist with a user-facing string explaining
why your app needs motion data. Without this key, the app crashes on first access.

```xml
<key>NSMotionUsageDescription</key>
<string>This app uses motion data to track your activity.</string>
```

### Authorization

Use the matching manager's `authorizationStatus()` or `authorizationStatus`
property when an API exposes one (`CMPedometer`, `CMMotionActivityManager`,
`CMAltimeter`, headphone motion, batched sensors, and submersion). Raw
`CMMotionManager` accelerometer/gyro/device-motion streams have no explicit
authorization request API; still ship the usage string and handle errors from
start/update callbacks.

```swift
import CoreMotion

let status = CMMotionActivityManager.authorizationStatus()
switch status {
case .notDetermined:
    // Will prompt on first use
    break
case .authorized:
    break
case .restricted, .denied:
    // Direct user to Settings
    break
@unknown default:
    break
}
```

## CMMotionManager: Sensor Data

Create exactly **one** `CMMotionManager` per app. Multiple instances degrade
sensor update rates.

```swift
import CoreMotion

let motionManager = CMMotionManager()
```

### Accelerometer Updates

The rest: https://github.com/dpearson2699/swift-ios-skills/blob/HEAD/skills/core-motion/SKILL.md
