Search code examples
iosswiftcore-motion

How to get exact time since iOS device booted?


I've encountered a problem. I need to get the exact TimeInterval since the device was booted. In the CoreMotion framework CMLogItem class have timestamp property, it returns exact time since device was booted. (link) This is necessary in order to measure the exact time for which the event occurred.

I tried the following code:

let timestamp = ProcessInfo.processInfo.systemUptime

but it returns different time than i need. Any help is appreciated, thanks in advance!


Solution

  • After investigation of the data you provide. It is possible to conclude that CMLog​Item:

    The CMLog​Item class is a base class for Core Motion classes that handle specific types of motion events. Objects of this class represent a piece of time-tagged data that can be logged to a file.

    CMLog​Item defines only a read-only timestamp property that records the time a motion-event measurement was taken. Not the exact time since device was booted.

    By ProcessInfo.processInfo.systemUptime you going to get time from the last time it was restarted.

    I believe data that you would like to obtain is quite specific and is under Private API of the iOS.