Chapter 17. Core Motion

Apple has finally brought some long-awaited features into the Core Motion framework. It’s especially exciting that the same capabilities, or some version of them, are also available on the Apple Watch. This is great news for us developers because we can program for the watch in a more native way, rather than reading this data from the user’s iPhone and sending it to the watch with Bluetooth.

There are a couple of key terms I’ll be using throughout this chapter that you need to know about:

Cadence

I use a cadence sensor on my bicycle. It helps me figure out how many times I spin my pedals, which can be crucial knowledge. Think about riding downhill on a bicycle, at a 45-degree angle, for 20 minutes out of a total 40-minute bike ride. Without accounting for cadence your total calories burned and effort will be miscalculated because you might not even have pedaled when going downhill. The watch actually includes a cadence sensor for running.

Pace

This is a ratio, dividing the time you have been moving by the distance. If you’re counting in meters, for instance, your pace might be 0.5 seconds per meter, meaning that you travelled 1 meter in half a second.

iOS devices can provide pace and cadence information when it’s available from the pedometer. Some pedometers might not have this information available. You can call the isPaceAvailable() class function of CMPedometer to check whether pace information is available. Similarly, you can call the isCadenceAvailable() ...

Get iOS 11 Swift Programming Cookbook 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.