Class

CMSensorRecorder

The gathering and retrieval of accelerometer data from a device.

Declaration

class CMSensorRecorder : NSObject

Overview

Use a sensor recorder to initiate the gathering of accelerometer data. Later, use the sensor recorder to fetch the recorded data so that you can analyze it. You might use the recorded data to assess specific types of motion and incorporate the results into your app.

To use a sensor recorder, create an instance of this class and call the recordAccelerometer(forDuration:) method to begin recording data. You do not need to stop the recording process explicitly. The system stops recording automatically when the specified time expires and no other apps extend the recording time. Listing 1 shows how to record 20 minutes worth of accelerometer data.

Listing 1

Recording accelerometer data

if CMSensorRecorder.isAccelerometerRecordingAvailable() {
    let recorder = CMSensorRecorder()
    recorder.recordAccelerometerForDuration(20 * 60)  // Record for 20 minutes
}

Topics

Checking the Availability of Sensor Recording

class func isAccelerometerRecordingAvailable() -> Bool

Returns a Boolean value indicating whether accelerometer recording is supported on the current device.

class func authorizationStatus() -> CMAuthorizationStatus

Returns a value indicating whether the app is authorized to record sensor data.

enum CMAuthorizationStatus

The authorization status for motion-related features.

class func isAuthorizedForRecording() -> Bool

Returns a Boolean value indicating whether the app is authorized to record sensor data.

Deprecated

Recording Accelerometer Data

func recordAccelerometer(forDuration: TimeInterval)

Begins recording accelerometer data for the specified period of time.

Retrieving Past Accelerometer Data

func accelerometerData(from: Date, to: Date) -> CMSensorDataList?

Retrieves the accelerometer data collected between the specified dates.

accelerometerDataSince:

Retrieves the accelerometer data for entries in the same batch.

Relationships

Inherits From

Conforms To

See Also

Accelerometers

Getting Raw Accelerometer Events

Retrieve data from the onboard accelerometers.

class CMAccelerometerData

A data sample from the device's three accelerometers.

class CMRecordedAccelerometerData

A single piece of accelerometer data that was recorded by the device.

class CMSensorDataList

A list of the accelerometer data recorded by the system.