iosobjective-ccore-motion

Calculating CMMotionActivity interval


I'm trying to calculate the time interval for a given CMMotionActivity.
A CMMotionActivity is a CMLogItem subclass, and as such - has a the property: @property(readonly, nonatomic) NSTimeInterval timestamp.
This time stamp is defined as:

The time stamp is the amount of time in seconds since the phone booted.

CMMotionActivity also has the property @property(readonly, nonatomic) NSDate *startDate.
I'm trying to figure out what is the interval for a given activity, aiming to come up with how much time the user was running or walking.
I'm using historical data (not reading events in real time).
I tried calculating the difference between motion events, but that seems wrong as I'm getting events in 5 second intervals but sometimes in much larger intervals.
Is there a way to calculate the "endDate" for a given CMMotionActivity?
I can't seem to find a way to do that in a reliable method either by observing a single event or a chain of events.


Solution

  • I believe a CMMotionActivity is generated every time the state of motion changes. Assuming this, given two CMMMotionActivity objects you can calculate the duration between the two events thereby determining how long the activity of stationary/walking/running/driving/uknowning was.