The iPhone is able to detect if you are walking, running, stationary, in a vehicle, or on a bike by using the motion sensors in the device. Back in 2018 I wrote about this in the tutorial called How to Use the CMMotionActivityManager. Today, we’ll update this for SwiftUI.

Since the iPhone 5s, iPhone has been able ot automatically track your activity, that being if you are stationary, in a vehicle, on a bike, and so on. iPhone keeps this data for seven days. You may have noticed when you were in a vehicle that the phone detects if you are driving and so on.
Core Motion provides a way for you to access this seven-day historical data as well as receive live updates on your current activity.
In this tutorial we’ll look at how to access this information to give an overview of your current day and what you have been doing.
It is important to note that the information provided by Core Motion has a confidence level. In the screenshot above you can see that I am stationary, but its confidence level is low. Now I was stationary when taking the screenshot, but the movement of the phone probably lowered that confidence level to low.
[Read more…]