Class: CMMotionManager
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)
-
- accelerometerActive
readonly
A Boolean value that indicates whether accelerometer updates are currently happening.
-
- accelerometerAvailable
readonly
A Boolean value that indicates whether an accelerometer is available on the device.
-
- accelerometerData
readonly
The latest sample of accelerometer data.
-
- accelerometerUpdateInterval
The interval, in seconds, for providing accelerometer updates to the block handler.
-
- 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.
-
- deviceMotion
readonly
The latest sample of device-motion data.
-
- deviceMotionActive
readonly
A Boolean value that determines whether the app is receiving updates from the device-motion service.
-
- deviceMotionAvailable
readonly
A Boolean value that indicates whether the device-motion service is available on the device.
-
- deviceMotionUpdateInterval
The interval, in seconds, for providing device-motion updates to the block handler.
-
- gyroActive
readonly
A Boolean value that determines whether gyroscope updates are currently happening.
-
- gyroAvailable
readonly
A Boolean value that indicates whether a gyroscope is available on the device.
-
- gyroData
readonly
The latest sample of gyroscope data.
-
- gyroUpdateInterval
The interval, in seconds, for providing gyroscope updates to the block handler.
-
- magnetometerActive
readonly
A Boolean value that determines whether magnetometer updates are currently happening.
-
- magnetometerAvailable
readonly
A Boolean value that indicates whether a magnetometer is available on the device.
-
- magnetometerData
readonly
The latest sample of magnetometer data.
-
- magnetometerUpdateInterval
The interval, in seconds, at which the system delivers magnetometer data to the block handler.
-
- showsDeviceMovementDisplay
Controls whether the device-movement display is shown.
Class Method Summary (collapse)
-
+ availableAttitudeReferenceFrames
Returns a bitmask specifying the available attitude reference frames on the device.
Instance Method Summary (collapse)
-
- startAccelerometerUpdates
Starts accelerometer updates without a handler.
-
- startAccelerometerUpdatesToQueue:withHandler:
Starts accelerometer updates on an operation queue and with a specified handler.
-
- startDeviceMotionUpdates
Starts device-motion updates without a block handler.
-
- startDeviceMotionUpdatesToQueue:withHandler:
Starts device-motion updates on an operation queue and using a specified block handler.
-
- startDeviceMotionUpdatesUsingReferenceFrame:
Starts device-motion updates using a reference frame but without a block handler.
-
- startDeviceMotionUpdatesUsingReferenceFrame:toQueue:withHandler:
Starts device-motion updates on an operation queue and using a specified reference frame and block handler.
-
- startGyroUpdates
Starts gyroscope updates without a handler.
-
- startGyroUpdatesToQueue:withHandler:
Starts gyroscope updates on an operation queue and with a specified handler.
-
- startMagnetometerUpdates
Starts magnetometer updates without a block handler.
-
- startMagnetometerUpdatesToQueue:withHandler:
Starts magnetometer updates on an operation queue and with a specified handler.
-
- stopAccelerometerUpdates
Stops accelerometer updates.
-
- stopDeviceMotionUpdates
Stops device-motion updates.
-
- stopGyroUpdates
Stops gyroscope updates.
-
- stopMagnetometerUpdates
Stops magnetometer updates.
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.)
- (Boolean) accelerometerAvailable (readonly)
A Boolean value that indicates whether an accelerometer is available on the device. (read-only)
- (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.
- (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.
- (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.
- (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.
- (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.
- (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.
- (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.)
- (Boolean) gyroAvailable (readonly)
A Boolean value that indicates whether a gyroscope is available on the device. (read-only)
- (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.
- (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.
- (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.)
- (Boolean) magnetometerAvailable (readonly)
A Boolean value that indicates whether a magnetometer is available on the device. (read-only)
- (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.
- (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.
- (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.
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:
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.
- (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.
- (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.
- (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.
- (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.
- (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.
- (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.
- (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.
- (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.
- (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.
- (Object) stopAccelerometerUpdates
Stops accelerometer updates.
- (Object) stopDeviceMotionUpdates
Stops device-motion updates.
- (Object) stopGyroUpdates
Stops gyroscope updates.
- (Object) stopMagnetometerUpdates
Stops magnetometer updates.