Question

I am using CMStepCounter and CMMotionActivityManager.

What I would like to do is work out my total walking time throughout the day, and from this, my average speed.

However, looking at the data in CMMotionActivityManager, it is clear than a number of steps throughout the day are actually logged during periods that are of 'unknown activity' and not walking or running. This does make sense, as you need to do a handful of steps for iOS to know you are walking. However, these add up over the course of any given day.

Querying CMMotionActivity, it is possible to get the timestamp of every event. However, whilst it is clear to me that every step must be timestamped in CMStepCounter, I can only see a method to return the total number of steps between two points in time. What would be great is if I could return an array of every step with its time stamp, and if so, how?

Many thanks.

Was it helpful?

Solution

With the current Core Motion API, you can't get an array of every step with its time stamp directly.

But you can use queryActivityStartingFromDate:toDate:toQueue:withHandler: to get an array of CMMotionActivity objects. Then use the time stamps to calculate the number of steps by calling queryStepCountStartingFrom:to:toQueue:withHandler:.

I don't think the M7 processor stores every step with its own time stamp. If you pass 1 as stepCounts to the method startStepCountingUpdatesToQueue:updateOn:withHandler:, you'll notice the handler is not executed on every step. Like the document says: The handler block is executed on a best effort basis each time the step count threshold is exceeded.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top