1
votes

I've developed an iOS app that collects data from both the phone's accelerometer and gyroscope, and it should process some data and send it over to the cloud.

The issue is that the CMAccelerometerData for ex. is based on CMLogItem which stores the timestamp as 'the amount of time in seconds since the phone booted' (apple documentation).

In order to find the real time in epoch (seconds since 1/1/1970) i tried to use NSProcessInfo().systemUptime, but it turned out that this value isn't accurate in some cases and gave me an offset of up to few hours!

In some posts it's mentioned that the uptime parameter is affected by system sleeps, and that could be the issue for these offsets (i must mention that when debugging there's no offset at all).

Any idea how can i get the timestamp of a CMLogItem? (even getting a 'close enough' timestamp is enough, i can skip the milli-seconds accuracy...)

Thanks in advance!

1

1 Answers

2
votes

If I've understood your question correctly, CMAccelerometerData and CMLogItem are not the types you need to work with.

CMSensorRecorder.accelerometerData(from:to:) returns CMSensorDataList, which allows to iterate over CMRecordedAccelerometerData objects, and each of them have startDate: Date parameter.

Additionaly, following extension will make iteration over samples easier: extension CMSensorDataList: Sequence { public func makeIterator() -> NSFastEnumerationIterator { return NSFastEnumerationIterator(self) } }