Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Core Motion

ASecurity

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.

3 stars
0 votes
0 copies
0 views
Added 9/28/2026
developmentswiftdocumentation

Security Analysis

A100/100

Scanned 9/28/2026

Install to Claude Code

$npx -y skills add thiennc-tesoglobal/ios-skills --skill core-motion --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Core Motion?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Core Motion
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/thiennc-tesoglobal-core-motion/badge)](https://www.skillsdirectory.com/skills/thiennc-tesoglobal-core-motion)

More formats (shields.io, HTML) on the badges page.

Files
SKILL.md
---
name: core-motion
description: "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."
---

# CoreMotion

Access accelerometer, gyroscope, attitude/device motion, pedometer, altitude, and specialized sensors using Core Motion. Targets Swift 6.3 / iOS 26+.

## Contents

- [Setup & Authorization](#setup--authorization)
- [Motion Manager & Raw Sensors](#motion-manager--raw-sensors)
- [Device Motion (Attitude & Gravity)](#device-motion-attitude--gravity)
- [Pedometer & Activity Recognition](#pedometer--activity-recognition)
- [Altimeter & Specialized Sensors](#altimeter--specialized-sensors)
- [Battery & Lifecycle](#battery--lifecycle)
- [Common Mistakes](#common-mistakes)
- [Review Checklist](#review-checklist)
- [References](#references)

## Setup & Authorization

Add `NSMotionUsageDescription` to Info.plist explaining why the app accesses motion sensors.

Check authorization status for managers exposing privacy controls (`CMPedometer`, `CMMotionActivityManager`, `CMAltimeter`):

```swift
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.

## Motion Manager & Raw Sensors

Maintain exactly **one** shared `CMMotionManager` instance per application to avoid sensor contention:

```swift
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()
    }
}
```

## Device Motion (Attitude & Gravity)

Prefer `CMDeviceMotion` over raw sensor data. It fuses accelerometer, gyro, and magnetometer data into clean attitude, user acceleration, and gravity vectors:

```swift
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
}
```

## Pedometer & Activity Recognition

Track steps, distance, and user movement state:

```swift
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") }
    }
}
```

## Altimeter & Specialized Sensors

- **CMAltimeter**: Track relative altitude changes or absolute barometric pressure (`startRelativeAltitudeUpdates`).
- **CMHeadphoneMotionManager**: Track head pose from AirPods for spatial audio interactions.
- **CMBatchedSensorManager (iOS 17+)**: Receive batched high-frequency workout motion data with low CPU wake overhead.
- **CMWaterSubmersionManager**: Track depth, temperature, and submersion state on supported Apple Watch hardware.

## Battery & Lifecycle

- Stop updates (`stopDeviceMotionUpdates()`) when views disappear or when the app transitions to the background.
- Select the lowest sensor update frequency adequate for your feature (e.g. 10–20 Hz for tilt detection; 60 Hz only for real-time physics/gaming).

## Common Mistakes

- **Instantiating multiple CMMotionManager objects**: Degrades system update rates and increases battery drain. Use a single shared manager.
- **Missing NSMotionUsageDescription**: The app crashes immediately upon accessing activity, pedometer, or altimeter services.
- **Not stopping updates on backgrounding**: Running motion updates indefinitely drains battery and causes system termination.
- **Using raw accelerometer for orientation**: Raw data includes gravity and user movement noise. Use `CMDeviceMotion.attitude` instead.
- **Omitting availability checks**: Always check `isAvailable` flags before calling `startUpdates`.

## Review Checklist

- [ ] `NSMotionUsageDescription` present and descriptive in Info.plist
- [ ] Single shared `CMMotionManager` instance used app-wide
- [ ] Sensor availability checked before initiating streams
- [ ] Updates explicitly halted when views dismiss or background transitions occur
- [ ] `CMDeviceMotion` used for orientation and tilt calculations instead of raw accelerometer
- [ ] Update intervals chosen conservatively to preserve battery life

## References

- Extended patterns (SwiftUI integration, batched sensor manager, headphone motion, water submersion): [references/motion-patterns.md](references/motion-patterns.md)
- [CoreMotion framework](https://sosumi.ai/documentation/coremotion)
- [CMMotionManager](https://sosumi.ai/documentation/coremotion/cmmotionmanager)
- [CMPedometer](https://sosumi.ai/documentation/coremotion/cmpedometer)
- [CMMotionActivityManager](https://sosumi.ai/documentation/coremotion/cmmotionactivitymanager)
- [CMDeviceMotion](https://sosumi.ai/documentation/coremotion/cmdevicemotion)
- [CMAltimeter](https://sosumi.ai/documentation/coremotion/cmaltimeter)
- [CMAbsoluteAltitudeData](https://sosumi.ai/documentation/coremotion/cmabsolutealtitudedata)
- [CMBatchedSensorManager](https://sosumi.ai/documentation/coremotion/cmbatchedsensormanager)
- [CMHeadphoneMotionManager](https://sosumi.ai/documentation/coremotion/cmheadphonemotionmanager)
- [CMWaterSubmersionManager](https://sosumi.ai/documentation/coremotion/cmwatersubmersionmanager)
- [Accessing submersion data](https://sosumi.ai/documentation/coremotion/accessing-submersion-data)
- [Getting processed device-motion data](https://sosumi.ai/documentation/coremotion/getting-processed-device-motion-data)

Attribution

thiennc-tesoglobalthiennc-tesoglobal
View sourceMore from thiennc-tesoglobal →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Browser Extension Developer

Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.

284972 votes

Seo Optimizer

SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.

2222 votes

Google Official Seo Guide

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

1862 votes

Tanstack Start

Build a full-stack TanStack Start app on Cloudflare Workers from scratch — SSR, file-based routing, server functions, D1+Drizzle, better-auth, Tailwind v4+shadcn/ui. Use whenever the user mentions TanStack Start, asks to scaffold a full-stack Cloudflare app with SSR, wants an SSR dashboard, or asks for a React 19 + Cloudflare Workers app with file-based routing and server functions — even if they don't name TanStack Start specifically. No template repo — Claude generates every file fresh per ...

10311 votes

Pentest

PTES-aligned adversarial security audit for backend, frontend, and mobile applications. Produces a CVSS-scored Hacker Report with verified PoCs and phased remediation.

5491 votes
View all in development →