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.

Magnetometer

Magnetometer - iOS Tutorial

From the course: Advanced iOS App Development: Core Motion

Start my 1-month free trial

Magnetometer

- A sensor shared by both core motion and core location is the magnetometer. For core location it is the compass. For more on compasses, check out core location, which uses location data to calibrate the compass accurately. In core motion, this is raw magnetometer data. From everything we've discussed so far, we know about noise. The magnetometer, being a raw sensor, has lots of noise. Let's add some code to learn how much noise there is in the magnetometer, and one way to keep it under control. Close up the console if you have it open. Add a new function above myAltimeter, and call it myMagnetometer. Check for the availability of the magnetometer. If not, print a not available message. If it is available, set to update the interval in 0.05 seconds. And we'll use the magnetometerUpdateInterval to do that. And we'll set it to 0.05 seconds. We'll push the magnetometer updates using the main queue. So again we'll use motionManager, startMagnetometerUpdates, and we'll use to withHandler…

Contents