Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

16. Core Motion > 16.1. Detecting the Availability of an Accelerometer

16.1. Detecting the Availability of an Accelerometer

Problem

In your program, you want to detect whether the accelerometer hardware is available.

Solution

Use the isAccelerometerAvailable method of CMMotionManager to detect the accelerometer hardware. The isAccelerometerActive method can also be used to detect whether the accelerometer hardware is currently sending updates to the program.

Let’s first make sure we have imported the required header files:

#import <UIKit/UIKit.h>
#import <CoreMotion/CoreMotion.h>

@interface Detecting_the_Availability_of_an_AccelerometerAppDelegate
           : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

Next, go on to detect the availability of accelerometer in the implementation file of our app delegate:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial