Introduction to Core Motion

Many applications, games in particular, love to use the accelerometer sensor in the iPhone to let the user precisely tilt their device as an interaction mechanism. In the last section we used UIDevice to get notifications about general orientation changes of the device, but there is a way to get much more precise data: the Core Motion framework. In this section, we'll be taking a look at some of the sensory data available through the CMMotionManager class.

Before we get started, let's reset our ViewController class to get rid of our UIDevice experiments, and start with our Core Motion experiments (you can create a new project if you don't want to get rid of the old code):

import UIKit import CoreMotion class ViewController: ...

Get Learning Xcode 8 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.