<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreMotion",
  "identifier" : "/documentation/CoreMotion/CMHeadphoneMotionManager/DeviceMotionHandler",
  "metadataVersion" : "0.1.0",
  "role" : "Type Alias",
  "symbol" : {
    "kind" : "Type Alias",
    "modules" : [
      "Core Motion",
      "CoreMotion"
    ],
    "preciseIdentifier" : "c:@T@CMHeadphoneDeviceMotionHandler"
  },
  "title" : "CMHeadphoneMotionManager.DeviceMotionHandler"
}
-->

# CMHeadphoneMotionManager.DeviceMotionHandler

The type of block callback for handling headphone-motion data.

```
typealias DeviceMotionHandler = (CMDeviceMotion?, (any Error)?) -> Void
```

## Discussion

The system calls `CMDeviceMotionHandler` blocks when there is device-motion data to process. You pass the block into [`startDeviceMotionUpdates(to:withHandler:)`](/documentation/CoreMotion/CMHeadphoneMotionManager/startDeviceMotionUpdates(to:withHandler:)) as the second argument. Blocks of this type return no value, but take two arguments:

- `motion`: A [`CMHeadphoneMotionManager`](/documentation/CoreMotion/CMHeadphoneMotionManager) object, which encapsulates other objects and a structure representing attitude, rotation rate, gravity, and user acceleration.
- `error`: An error object representing an error when providing gyroscope data. If an error occurs, you should stop gyroscope updates and inform the user of the problem. If there is no error, this argument is `nil`. Core Motion errors are of the [`CMErrorDomain`](/documentation/CoreMotion/CMErrorDomain) domain and the [`CMError`](/documentation/CoreMotion/CMError) type.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)