Class: CMMotionManager

Inherits:
NSObject show all

Overview

A CMMotionManager object is the gateway to the motion services provided by iOS. These services provide an app with accelerometer data, rotation-rate data, magnetometer data, and other device-motion data such as attitude. These types of data originate with a device’s accelerometers and (on some models) its magnetometer and gyroscope.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Instance Attribute Details

- (Boolean) accelerometerActive (readonly)

A Boolean value that indicates whether accelerometer updates are currently happening. (read-only) This property indicates whether startAccelerometerUpdatesToQueue:withHandler: or startAccelerometerUpdates has been called since the last time stopAccelerometerUpdates was called. (If the start methods hadn’t been called, the app could be getting updates from the accelerometer after calling, for example, startDeviceMotionUpdates, but this property would return NO.)

Returns:

  • (Boolean)

- (Boolean) accelerometerAvailable (readonly)

A Boolean value that indicates whether an accelerometer is available on the device. (read-only)

Returns:

  • (Boolean)

- (CMAccelerometerData) accelerometerData (readonly)

The latest sample of accelerometer data. (read-only) If no accelerometer data is available, the value of this property is nil. An app that is receiving accelerometer data after calling startAccelerometerUpdates periodically checks the value of this property and processes the acceleration data.

Returns:

- (NSTimeInterval) accelerometerUpdateInterval

The interval, in seconds, for providing accelerometer updates to the block handler. The system supplies accelerometer updates to the block handler specified in startAccelerometerUpdatesToQueue:withHandler: at regular intervals determined by the value of this property. The interval units are in seconds. The value of this property is capped to minimum and maximum values; the maximum value is determined by the maximum frequency supported by the hardware. If your app is sensitive to the intervals of acceleration data, it should always check the timestamps of the delivered CMAccelerometerData instances to determine the true update interval.

Returns:

  • (NSTimeInterval)

- (CMAttitudeReferenceFrame) attitudeReferenceFrame (readonly)

Returns either the reference frame currently being used or the default attitude reference frame (read-only) If device motion is active, this property returns the reference frame currently in use. If device motion is not active but has been active since the app was last launched, this property returns the last frame used. If device motion has not been active since the app was last launched, this property returns the default attitude reference frame for the device. If device motion is not available on the device, the value is undefined.

- (CMDeviceMotion) deviceMotion (readonly)

The latest sample of device-motion data. (read-only) If no device-motion data is available, the value of this property is nil. An app that is receiving device-motion data after calling startDeviceMotionUpdates periodically checks the value of this property and processes the device-motion data.

Returns:

- (Boolean) deviceMotionActive (readonly)

A Boolean value that determines whether the app is receiving updates from the device-motion service. (read-only) This property indicates whether startDeviceMotionUpdatesToQueue:withHandler: or startDeviceMotionUpdates has been called since the last time stopDeviceMotionUpdates was called.

Returns:

  • (Boolean)

- (Boolean) deviceMotionAvailable (readonly)

A Boolean value that indicates whether the device-motion service is available on the device. (read-only) The device-motion service is available if a device has both an accelerometer and a gyroscope. Because all devices have accelerometers, this property is functionally equivalent to gyroAvailable.

Returns:

  • (Boolean)

- (NSTimeInterval) deviceMotionUpdateInterval

The interval, in seconds, for providing device-motion updates to the block handler. The system supplies device-motion updates to the block handler specified in startDeviceMotionUpdatesToQueue:withHandler: at regular intervals determined by the value of this property. The interval units are in seconds. The value of this property is capped to minimum and maximum values; the maximum value is determined by the maximum frequency supported by the hardware. If your app is sensitive to the intervals of device-motion data, it should always check the timestamps of the delivered CMDeviceMotion instances to determine the true update interval.

Returns:

  • (NSTimeInterval)

- (Boolean) gyroActive (readonly)

A Boolean value that determines whether gyroscope updates are currently happening. (read-only) This property indicates whether startGyroUpdatesToQueue:withHandler: or startGyroUpdates has been called since the last time stopGyroUpdates was called. (If the start methods hadn’t been called, the app could be getting updates from the gyroscope after calling, for example, startDeviceMotionUpdates, but this property would return NO.)

Returns:

  • (Boolean)

- (Boolean) gyroAvailable (readonly)

A Boolean value that indicates whether a gyroscope is available on the device. (read-only)

Returns:

  • (Boolean)

- (CMGyroData) gyroData (readonly)

The latest sample of gyroscope data. (read-only) If no gyroscope data is available, the value of this property is nil. An app that is receiving gyroscope data after calling startGyroUpdates periodically checks the value of this property and processes the gyroscope data.

Returns:

- (NSTimeInterval) gyroUpdateInterval

The interval, in seconds, for providing gyroscope updates to the block handler. The system supplies gyroscope (that is, rotation rate) updates to the block handler specified in startGyroUpdatesToQueue:withHandler: at regular intervals determined by the value of this property. The interval units are in seconds. The value of this property is capped to minimum and maximum values; the maximum value is determined by the maximum frequency supported by the hardware. If your app is sensitive to the intervals of gyroscope data, it should always check the timestamps of the delivered CMGyroData instances to determine the true update interval.

Returns:

  • (NSTimeInterval)

- (Boolean) magnetometerActive (readonly)

A Boolean value that determines whether magnetometer updates are currently happening. (read-only) This property indicates whether the startMagnetometerUpdatesToQueue:withHandler: or startMagnetometerUpdates method has been called since the last time the stopMagnetometerUpdates method was called. (If the start methods hadn’t been called, the app could be getting updates from the magnetometer after calling, for example, startDeviceMotionUpdates, but this property would return NO.)

Returns:

  • (Boolean)

- (Boolean) magnetometerAvailable (readonly)

A Boolean value that indicates whether a magnetometer is available on the device. (read-only)

Returns:

  • (Boolean)

- (CMMagnetometerData) magnetometerData (readonly)

The latest sample of magnetometer data. (read-only) If no magnetometer data is available, the value of this property is nil. An app that is receiving magnetometer data after calling startMagnetometerUpdates periodically checks the value of this property and processes the gyroscope data.

Returns:

- (NSTimeInterval) magnetometerUpdateInterval

The interval, in seconds, at which the system delivers magnetometer data to the block handler. The supplies magnetometer data to the block handler specified in startMagnetometerUpdatesToQueue:withHandler: at regular intervals determined by the value of this property. The interval unit are in seconds. The value of this property is capped to minimum and maximum values; the maximum value is determined by the maximum frequency supported by the hardware. If your app is sensitive to the intervals of magnetometer data, it should always check the timestamps of the delivered CMMagnetometerData instances to determine the true update interval.

Returns:

  • (NSTimeInterval)

- (Boolean) showsDeviceMovementDisplay

Controls whether the device-movement display is shown. When a device requires movement (for example, to calibrate the compass), the value of this property indicates if the system’s device-movement display should be shown. When a device requires movement, the block handler of type CMDeviceMotionHandler reports the CMErrorDeviceRequiresMovement error once. By default, this property is NO.

Returns:

  • (Boolean)

Class Method Details

+ (Integer) availableAttitudeReferenceFrames

Returns a bitmask specifying the available attitude reference frames on the device. For example, to determine whether CMAttitudeReferenceFrameXMagneticNorthZVertical is available on the device, you would perform the following test:

Returns:

Instance Method Details

- (Object) startAccelerometerUpdates

Starts accelerometer updates without a handler. You can get the latest accelerometer data through the accelerometerData property. You must call stopAccelerometerUpdates when you no longer want your app to process accelerometer updates.

Returns:

- (Object) startAccelerometerUpdatesToQueue(queue, withHandler:handler)

Starts accelerometer updates on an operation queue and with a specified handler. You must call stopAccelerometerUpdates when you no longer want your app to process accelerometer updates.

Parameters:

  • queue (NSOperationQueue)

    An operation queue provided by the caller. Because the processed events might arrive at a high rate, using the main operation queue is not recommended.

  • handler (CMAccelerometerHandler)

    A block that is invoked with each update to handle new accelerometer data. The block must conform to the CMAccelerometerHandler type.

Returns:

- (Object) startDeviceMotionUpdates

Starts device-motion updates without a block handler. You can get the latest device-motion data through the deviceMotion property. You must call stopDeviceMotionUpdates when you no longer want your app to process device-motion updates. This method uses the reference frame returned by attitudeReferenceFrame for device-motion updates.

Returns:

- (Object) startDeviceMotionUpdatesToQueue(queue, withHandler:handler)

Starts device-motion updates on an operation queue and using a specified block handler. This method uses the reference frame returned by attitudeReferenceFrame for device-motion updates. You must call stopDeviceMotionUpdates when you no longer want your app to process device-motion updates.

Parameters:

  • queue (NSOperationQueue)

    An operation queue provided by the caller. Because the processed events might arrive at a high rate, using the main operation queue is not recommended.

  • handler (CMDeviceMotionHandler)

    A block that is invoked with each update to handle new device-motion data. The block must conform to the CMDeviceMotionHandler type.

Returns:

- (Object) startDeviceMotionUpdatesUsingReferenceFrame(referenceFrame)

Starts device-motion updates using a reference frame but without a block handler. You can get the latest device-motion data through the deviceMotion property. You must call stopDeviceMotionUpdates when you no longer want your app to process device-motion updates.

Parameters:

  • referenceFrame (CMAttitudeReferenceFrame)

    A constant identifying the reference frame to use for device-motion updates.

Returns:

- (Object) startDeviceMotionUpdatesUsingReferenceFrame(referenceFrame, toQueue:queue, withHandler:handler)

Starts device-motion updates on an operation queue and using a specified reference frame and block handler. You must call stopDeviceMotionUpdates when you no longer want your app to process device-motion updates.

Parameters:

  • referenceFrame (CMAttitudeReferenceFrame)

    A constant identifying the reference frame to use for device-motion updates.

  • queue (NSOperationQueue)

    An operation queue provided by the caller. Because the processed events might arrive at a high rate, using the main operation queue is not recommended.

  • handler (CMDeviceMotionHandler)

    A block that is invoked with each update to handle new device-motion data. The block must conform to the CMDeviceMotionHandler type.

Returns:

- (Object) startGyroUpdates

Starts gyroscope updates without a handler. You can get the latest gyroscope data through the gyroData property. You must call stopGyroUpdates when you no longer want your app to process gyroscope updates.

Returns:

- (Object) startGyroUpdatesToQueue(queue, withHandler:handler)

Starts gyroscope updates on an operation queue and with a specified handler. You must call stopGyroUpdates when you no longer want your app to process gyroscope updates.

Parameters:

  • queue (NSOperationQueue)

    An operation queue provided by the caller. Because the processed events might arrive at a high rate, using the main operation queue is not recommended.

  • handler (CMGyroHandler)

    A block that is invoked with each update to handle new gyroscope data. The block must conform to the CMGyroHandler type.

Returns:

- (Object) startMagnetometerUpdates

Starts magnetometer updates without a block handler. You can get the latest magnetometer data through the magnetometerData property. You must call stopMagnetometerUpdates when you no longer want your app to process magnetometer updates.

Returns:

- (Object) startMagnetometerUpdatesToQueue(queue, withHandler:handler)

Starts magnetometer updates on an operation queue and with a specified handler. You must call stopMagnetometerUpdates when you no longer want your app to process magnetometer updates.

Parameters:

  • queue (NSOperationQueue)

    An operation queue provided by the caller. Because the processed events might arrive at a high rate, using the main operation queue is not recommended.

  • handler (CMMagnetometerHandler)

    A block that is invoked with each update to handle new magnetometer data. The block must conform to the CMMagnetometerHandler type.

Returns:

- (Object) stopAccelerometerUpdates

Stops accelerometer updates.

Returns:

- (Object) stopDeviceMotionUpdates

Stops device-motion updates.

Returns:

- (Object) stopGyroUpdates

Stops gyroscope updates.

Returns:

- (Object) stopMagnetometerUpdates

Stops magnetometer updates.

Returns: