Modules.CoreMotion
> Modules.CoreMotion

Allows Titanium client applications to access Apple's CoreMotion APIs.

The Core Motion module provides access to Apple's CoreMotion APIs. The Core Motion module provides support for monitoring various hardware sensors on iOS devices, such as the accelerometer, gyroscope, and magnetometer. The Core Motion module allows you to access the metrics provided by these sensors.

For instruction and examples of using the Core Motion Module, see the Core Motion Module guide.

Requirements

This module only works with devices running iOS 7 and later. Not all devices have the same hardware sensors, so all features may not be available for all devices. Be sure to use the API to check the device for the existence of a feature.

You can only test the Core Motion module on a device. The Core Motion API cannot be tested on the iOS simulator.

Some features may require permission to use "Motion Activity". iOS requires the user's approval to use the "Motion Activity" permission. When the application uses the Core Motion API for the first time, iOS prompts the user to either approve or deny access to the Core Motion features of the device. The user can change the permission settings with Settings > Privacy.

Getting Started

Once you have installed the module and added it as a depedency, use require() to access it from JavaScript:

var CoreMotion = require("ti.coremotion");

// The `CoreMotion` variable is a reference to the Module object.  Use this reference to make
// subsequent calls to the CoreMotion Module API. The following example shows the step counting
// API of `CoreMotion`.

var pedometer = CoreMotion.createPedometer();

// This code checks to see if the device can gather step counting data
if (pedometer.isStepCountingAvailable()) {
    // If it can, it starts the step counter and outputs the data to the console
    pedometer.startPedometerUpdates(function(e) {
        Ti.API.info(JSON.stringify(e));
    });
} else {
    Ti.API.warn('This device does not support counting steps.');
}

Sample Application

The module ZIP file contains a Core Motion sample applications in example/app.js.

Further Reading

  • 3.3.0
  • 3.3.0
Defined By

Properties

Describes the same reference frame as ATTITUDE_REFERENCE_FRAME_X_ARBITRARY_Z_VERTICAL except that the magnetometer, w...

Describes the same reference frame as ATTITUDE_REFERENCE_FRAME_X_ARBITRARY_Z_VERTICAL except that the magnetometer, when available and calibrated, is used to improve long-term yaw accuracy. Using this constant instead of ATTITUDE_REFERENCE_FRAME_X_ARBITRARY_Z_VERTICAL results in increased CPU usage.

Modules.CoreMotion
: Numberreadonly
Describes a reference frame in which the Z axis is vertical and the X axis points in an arbitrary direction in the ho...

Describes a reference frame in which the Z axis is vertical and the X axis points in an arbitrary direction in the horizontal plane.

Modules.CoreMotion
: Numberreadonly
Describes a reference frame in which the Z axis is vertical and the X axis points toward magnetic north. ...

Describes a reference frame in which the Z axis is vertical and the X axis points toward magnetic north. Note that using this reference frame may require device movement to calibrate the magnetometer.

Modules.CoreMotion
: Numberreadonly
Describes a reference frame in which the Z axis is vertical and the X axis points toward true north. ...

Describes a reference frame in which the Z axis is vertical and the X axis points toward true north. Note that using this reference frame may require device movement to calibrate the magnetometer. It also requires the location to be available in order to calculate the difference between magnetic and true north.

Modules.CoreMotion
ERROR_DEVICE_REQUIRES_MOVEMENT : Numberreadonly

The device must move for a sampling of motion data to occur.

The device must move for a sampling of motion data to occur.

Modules.CoreMotion
ERROR_INVALID_PARAMETER : Numberreadonly

An invalid parameter was specified.

An invalid parameter was specified.

Modules.CoreMotion
ERROR_MOTION_ACTIVITY_NOT_AUTHORIZED : Numberreadonly

The app is not currently authorized to use motion activity support.

The app is not currently authorized to use motion activity support.

Modules.CoreMotion
ERROR_MOTION_ACTIVITY_NOT_AVAILABLE : Numberreadonly

Motion activity support is not available on the current device.

Motion activity support is not available on the current device.

Modules.CoreMotion
ERROR_MOTION_ACTIVITY_NOT_ENTITLED : Numberreadonly

The app is missing a required entitlement.

The app is missing a required entitlement.

Modules.CoreMotion
ERROR_NULL : Numberreadonly

No error.

No error.

Modules.CoreMotion
: Numberreadonly
True north is not available on this device. ...

True north is not available on this device. This usually indicates that the device's location is not yet available.

Modules.CoreMotion
ERROR_UNKNOWN : Numberreadonly

An unknown error occurred.

An unknown error occurred.

Modules.CoreMotion
MAGNETIC_FIELD_CALIBRATION_ACCURACY_HIGH : Numberreadonly

The accuracy of the magnetic field calibration is high.

The accuracy of the magnetic field calibration is high.

Modules.CoreMotion
MAGNETIC_FIELD_CALIBRATION_ACCURACY_LOW : Numberreadonly

The accuracy of the magnetic field calibration is low.

The accuracy of the magnetic field calibration is low.

Modules.CoreMotion
MAGNETIC_FIELD_CALIBRATION_ACCURACY_MEDIUM : Numberreadonly

The accuracy of the magnetic field calibration is medium.

The accuracy of the magnetic field calibration is medium.

Modules.CoreMotion
MAGNETIC_FIELD_CALIBRATION_ACCURACY_UNCALIBRATED : Numberreadonly

The magnetic field estimate is not calibrated.

The magnetic field estimate is not calibrated.

Modules.CoreMotion
MOTION_ACTIVITY_CONFIDENCE_HIGH : Numberreadonly

Confidence is high.

Confidence is high.

Modules.CoreMotion
MOTION_ACTIVITY_CONFIDENCE_LOW : Numberreadonly

Confidence is low.

Confidence is low.

Modules.CoreMotion
MOTION_ACTIVITY_CONFIDENCE_MEDIUM : Numberreadonly

Confidence is good.

Confidence is good.

apiName : Stringreadonly

The name of the API that this proxy corresponds to.

The name of the API that this proxy corresponds to.

The value of this property is the fully qualified name of the API. For example, Button returns Ti.UI.Button.

  • 3.2.0
  • 3.2.0
  • 3.2.0

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.

  • 3.6.0
Defined By

Methods

Modules.CoreMotion
( [parameters] ) : Modules.CoreMotion.Accelerometer
Creates and returns an instance of Modules.CoreMotion.Accelerometer. ...

Creates and returns an instance of Modules.CoreMotion.Accelerometer.

  • 5.2.0
  • 5.2.0

Parameters

Returns

Modules.CoreMotion
( [parameters] ) : Modules.CoreMotion.DeviceMotion
Creates and returns an instance of Modules.CoreMotion.DeviceMotion. ...

Creates and returns an instance of Modules.CoreMotion.DeviceMotion.

  • 5.2.0
  • 5.2.0

Parameters

Returns

Modules.CoreMotion
( [parameters] ) : Modules.CoreMotion.Gyroscope
Creates and returns an instance of Modules.CoreMotion.Gyroscope. ...

Creates and returns an instance of Modules.CoreMotion.Gyroscope.

  • 5.2.0
  • 5.2.0

Parameters

Returns

Modules.CoreMotion
( [parameters] ) : Modules.CoreMotion.Magnetometer
Creates and returns an instance of Modules.CoreMotion.Magnetometer. ...

Creates and returns an instance of Modules.CoreMotion.Magnetometer.

  • 5.2.0
  • 5.2.0

Parameters

Returns

Modules.CoreMotion
( [parameters] ) : Modules.CoreMotion.MotionActivity
Creates and returns an instance of Modules.CoreMotion.MotionActivity. ...

Creates and returns an instance of Modules.CoreMotion.MotionActivity.

  • 5.2.0
  • 5.2.0

Parameters

Returns

Modules.CoreMotion
( [parameters] ) : Modules.CoreMotion.Pedometer
Creates and returns an instance of Modules.CoreMotion.Pedometer. ...

Creates and returns an instance of Modules.CoreMotion.Pedometer.

  • 5.2.0
  • 5.2.0

Parameters

Returns

Modules.CoreMotion
( [parameters] ) : Modules.CoreMotion.StepCounterdeprecated
Creates and returns an instance of Modules.CoreMotion.StepCounter. ...

Creates and returns an instance of Modules.CoreMotion.StepCounter.

deprecated

5.2.0 This API was deprecated by Apple in iOS 7 and is only available for backward compatibility with older versions of this module. It will be removed in the next release. Please use <Modules.CoreMotion.Pedometer> API instead, which provides the same functionality including new properties like floorCount and distance.

  • 5.2.0
  • 5.2.0

Parameters

Returns

Gets the value of the apiName property. ...

Gets the value of the apiName property.

  • 3.2.0
  • 3.2.0
  • 3.2.0

Returns

  • String
Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Sets the value of the lifecycleContainer property. ...

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void