UIAccelerometer Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 2.0 and later.
Deprecated in iOS 5.0.
Declared in
UIAccelerometer.h
Related sample code

Overview

The UIAccelerometer class lets you register to receive acceleration-related data from the onboard hardware. As a device moves, its hardware reports linear acceleration changes along the primary axes in three-dimensional space. You can use this data to detect both the current orientation of the device (relative to the ground) and any instantaneous changes to that orientation. You might use instantaneous changes as input to a game or to initiate some action in your application.

You do not create accelerometer objects directly. Instead, you use the shared UIAccelerometer object to specify the interval at which you want to receive events and then set its delegate property. Upon assigning your delegate object, the accelerometer object begins delivering acceleration events to your delegate immediately at the specified interval. Events are always delivered on the main thread of your application.

The maximum frequency for accelerometer updates is based on the available hardware. You can request updates less frequently but cannot request them more frequently than the hardware maximum. Once you assign your delegate, however, updates are delivered regularly at the frequency you requested, whether or not the acceleration data actually changed. Your delegate is responsible for filtering out any unwanted updates and for ensuring that the amount of change is significant enough to warrant taking action.

For more information about the data delivered to your observer, see UIAcceleration Class Reference. For information about implementing your delegate object, see UIAccelerometerDelegate Protocol Reference.

Tasks

Getting the Shared Accelerometer Object

Accessing the Accelerometer Properties

Properties

delegate

The delegate object you want to receive acceleration events.

@property(nonatomic, assign) id<UIAccelerometerDelegate> delegate
Discussion

The UIAccelerometerDelegate is a formal protocol, so your delegate object must implement the method it defines. The shared accelerometer object delivers the acceleration data to your delegate at the specified interval. It delivers these events on the main thread of your application when it is in the NSDefaultRunLoopMode run loop mode.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIAccelerometer.h

updateInterval

The interval at which to deliver acceleration data to the delegate.

@property(nonatomic) NSTimeInterval updateInterval
Discussion

This property is measured in seconds. The value of this property is capped to certain minimum and maximum values. The maximum value is determined by the maximum frequency supported by the hardware. To ensure that it can deliver device orientation events in a timely fashion, the system determines the appropriate minimum value based on its needs.

Changes to this property are delivered synchronously to the accelerometer hardware. You may change this property while the delegate is non-nil.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIAccelerometer.h

Class Methods

sharedAccelerometer

Returns the shared accelerometer object for the system.

+ (UIAccelerometer *)sharedAccelerometer
Return Value

The systemwide accelerometer object.

Discussion

Always use this method to retrieve the shared system accelerometer object. Do not create new instances of the UIAccelerometer class.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIAccelerometer.h