From the course: Advanced iOS App Development: Core Motion

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Altimeter

Altimeter - iOS Tutorial

From the course: Advanced iOS App Development: Core Motion

Start my 1-month free trial

Altimeter

[Narrator]- As you just heard in later model devices, the altimeter measures barometric pressure in kilopascals through core motion. You do not reach it in device motion or even the motion manager, but as a raw sensor. Let's add some code to our fencing project to detect altitude changes. Make a new function in the fencing demo called 'myAltimeter'. Close the console. Just above 'myDeviceMotion', make a new function called 'myAltimeter'. Check for the availability of the altimeter. You do that with the 'isRelativeAltitudeAvailable' class function. If it's not available, print to the console that we don't have one in the else statement. Altimeters only have push updates. We'll make an altimeter object and then start updates. First, head up to the top of the code and make a property for the class for the altimeter. We'll do a 'let altimeter = CMAltimeter'. Back in the 'myAltimeter' function, start the updates: 'altimeter.startRelativeAltitudeUpdates', and we'll use the one with the…

Contents