iOS Developer Library — Prerelease

Developer

Core Motion Framework Reference CMMotionActivity Class Reference

Options
Deployment Target:

On This Page
Language:

CMMotionActivity

The CMMotionActivity class contains the data for a single motion update event. On devices that support motion, you can use a CMMotionActivityManager object to request updates when the current type of motion changes. When a change occurs, the update information is packaged into a CMMotionActivity object and sent to your app.

The motion-related properties of this class are not mutually exclusive. In other words, it is possible for more than one of the motion-related properties to contain the value YEStrue. For example, if the user was driving in a car and the car stopped at a red light, the update event associated with that change in motion would have both the automotive and stationary properties set to YEStrue. It is also possible for all of the properties to be set to NOfalse when the device is in motion but the movement does not correlate to walking, running, cycling or automotive travel.

You do not create instances of this class yourself. The CMMotionActivityManager object creates them and sends them to the handler block you registered. For more information about how to initiate the delivery of motion activity updates to your app, see CMMotionActivityManager Class Reference.

  • A Boolean indicating whether the device is stationary. (read-only)

    Declaration

    Swift

    var stationary: Bool { get }

    Objective-C

    @property(readonly, nonatomic) BOOL stationary

    Availability

    Available in iOS 7.0 and later.

  • A Boolean indicating whether the device is on a walking person. (read-only)

    Declaration

    Swift

    var walking: Bool { get }

    Objective-C

    @property(readonly, nonatomic) BOOL walking

    Availability

    Available in iOS 7.0 and later.

  • A Boolean indicating whether the device is on a running person. (read-only)

    Declaration

    Swift

    var running: Bool { get }

    Objective-C

    @property(readonly, nonatomic) BOOL running

    Availability

    Available in iOS 7.0 and later.

  • A Boolean indicating whether the device is in an automobile. (read-only)

    Declaration

    Swift

    var automotive: Bool { get }

    Objective-C

    @property(readonly, nonatomic) BOOL automotive

    Availability

    Available in iOS 7.0 and later.

  • A Boolean indicating whether the device is in an bicycle. (read-only)

    Declaration

    Swift

    var cycling: Bool { get }

    Objective-C

    @property(readonly, nonatomic) BOOL cycling

    Availability

    Available in iOS 8.0 and later.

  • A Boolean indicating whether the type of motion is unknown. (read-only)

    Declaration

    Swift

    var unknown: Bool { get }

    Objective-C

    @property(readonly, nonatomic) BOOL unknown

    Discussion

    This property is set to YEStrue when there is no way to estimate the current type of motion. For example, this property might be YEStrue if the device was turned on recently and not enough motion data had been gathered to determine the type of motion.

    Availability

    Available in iOS 7.0 and later.

  • The confidence that the motion data is accurate.

    Declaration

    Swift

    enum CMMotionActivityConfidence : Int { case Low case Medium case High }

    Objective-C

    typedef enum : NSInteger { CMMotionActivityConfidenceLow = 0, CMMotionActivityConfidenceMedium, CMMotionActivityConfidenceHigh }CMMotionActivityConfidence;

    Constants

    • Low

      CMMotionActivityConfidenceLow

      Confidence is low.

      Available in iOS 7.0 and later.

    • Medium

      CMMotionActivityConfidenceMedium

      Confidence is good.

      Available in iOS 7.0 and later.

    • High

      CMMotionActivityConfidenceHigh

      Confidence is high.

      Available in iOS 7.0 and later.

    Import Statement

    Objective-C

    @import CoreMotion;

    Swift

    import CoreMotion

    Availability

    Available in iOS 7.0 and later.