In this tutorial we will have a look at how to set up the magnetometer using the Core Motion framework. Just like enabling the accelerometer or gyroscope, enabling the magnetometer is also extremely simple to do.
The magnetometer is used to provide measurements of the earths magnetic field relative to the device. You can use the magnetometer to derive the heading, but to do so you would need input from other sensors to help with the calculations. If you are more interested in using the compass, then Apple does cater for that with the CLHeading class which we will look at in another tutorial.
We will begin with a single view application, and work in ViewController.swift. [Read more…]
In todays tutorial we will look at the long-running query that is available for HKActivitySummaryQuery. This particular version of the query keeps running in the background and monitors for changes. Each time the health store is updated with new data; either stand, exercise, or active calories; the update handler will be called which will allow you to refresh your views, should you need to.
The easiest way to think about this query is to look at the activity ring, or a collection of activity rings as pictured here. Apple Watch owners will be very aware of what each ring represents. This class allows you to fetch the data that builds up this ring, but also pass it to the HKActivityRingView to represent those numbers in a familiar format to Apple Watch users. For those wanting to use the Apple Watch version of the ring, Apple also has made available WKInterfaceActivityRing.