'CMPedometer saving steps timestamp

I'm building an iOS app in which I need to save the timestamp of each step that the user makes. Im using CoreMotion CMPedometer, but the method startUpdates only outputs the total number of steps that the user did from a start time to a end time.

The workaround I am using is: in every block of returned steps I use the startDate and endDate, and calculate the number of seconds per step, and them set the timestamp of each step in a linear way using the seconds per step. Then, I set the next startDate equal to the endDate of the previous block. But this is not near precise, since no blocks are returned when there is no activity, resulting in wrong results.

Is there anyway I can get the exact step times? Or at least a more precise way?



Solution 1:[1]

This sounds like the classic "fencepost problem"

Let's say I am a very slow walker. From 9 am to 10 am I do 4 steps, then nothing between 10am and 11, then from 11 to 12 I do another 4 steps

From 9 to 10:

9       10
|1|2|3|4|

What would it mean for a step to have an instantaneous timestamp?

Step 1 is from 9am to 9:15am, or you could say 9:07.5 is when the leg is vertical? Or are we interested in the exact time when the foot first touches the floor, or when you are at an average point in your step when the leg is vertical? Or do we say step 1 was from 9:00 to 9:15, or more generally that I made 4 steps in 1 hour? And doing that also has the advantage that these time periods are computed properties and not stored Dates that don't add any information over the 'n steps in time interval' representation.

Why would you set the next startDate equal to the endDate of the previous block - people aren't always making steps... I didn't start my first step from 11 to 12 at 10 am, I started it at 11am, and it was finished at 11:15.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shadowrun