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!
答案 0 :(得分:1)
如果我已正确理解您的问题,CMAccelerometerData
和CMLogItem
不是您需要使用的类型。
CMSensorRecorder.accelerometerData(from:to:)
返回CMSensorDataList
,允许迭代CMRecordedAccelerometerData
个对象,每个对象都有startDate: Date
个参数。
另外,以下扩展将使样本的迭代更容易:
extension CMSensorDataList: Sequence {
public func makeIterator() -> NSFastEnumerationIterator {
return NSFastEnumerationIterator(self)
}
}