CMDeviceMotion
Now, these last two sections are really great to get some low level data from your iPhone's sensors, but the CMMotionManager
provides a great way to get calibrated data with bias removed automatically by Core Motion: CMDeviceMotion
. This class contains a handful of sensory data that has already been processed by algorithms in Core Motion.
Since we're already familiar with the way we configure CMMotionManager
to begin polling sensors, I'll just leave the code here for you to look at; you should already know how it works:
class ViewController: UIViewController { let motionManager = CMMotionManager() let motionQueue = OperationQueue() override func viewDidLoad() { super.viewDidLoad() if motionManager.isDeviceMotionAvailable { motionManager.deviceMotionUpdateInterval = 0.25 motionManager.startDeviceMotionUpdates(to: motionQueue, withHandler: onMotionUpdate) } } func onMotionUpdate...