CoreMotionReporter

open class CoreMotionReporter: ActivityReporter

Dumps latest activity data from CoreMotion to a SQLite database and returns previously archived activity data.

See HealthKit/README.md for detailed instructions.

  • The filesystem path to the database.

    Declaration

    Swift

    open let databaseLocation: String
  • Designated initializer.

    Declaration

    Swift

    public init(path: String)

    Parameters

    path

    The filesystem path to the SQLite database

  • Archive all available activities (that happened since the last sampling) to our SQLite database.

    The data store is lossless, meaning that all aspects of the activities are preserved. The db format has been kept as compact as possible, using NSDate’s timeIntervalSinceReferenceDate to store the date which also serves as primary key. In my setup, iPhone 6S plus Apple Watch, this amounts to 420 KB of data for a week.

    Declaration

    Swift

    open func archiveActivities(processor: CoreMotionActivityInterpreter? = nil, callback: @escaping ((_ numNewActivities: Int, _ error: Error?) -> Void))

    Parameters

    processor

    A CoreMotionActivityInterpreter instance to handle CMMotionActivity processing (not interpretation!) before the callback returns; uses an CoreMotionStandardActivityInterpreter instance if none is provided

    callback

    The callback to call when done, with an error if something happened, nil otherwise. Called on the main queue

  • Declaration

    Swift

    open func reportForActivityPeriod(startingAt start: Date, until: Date, callback: @escaping ((_ period: ActivityReportPeriod?, _ error: Error?) -> Void))

    Parameters

    startingAt

    The start date

    until

    The end date

    callback

    The callback to call when all activities have been retrieved

  • Retrieves activities performed between two given dates and runs an interpreter over the results which may process the activities in a certain way.

    Declaration

    Swift

    open func reportForActivityPeriod(startingAt start: Date, until: Date? = nil, interpreter: CoreMotionActivityInterpreter? = nil, callback: @escaping ((_ report: ActivityReportPeriod?, _ error: Error?) -> Void))

    Parameters

    startingAt

    The start date

    until

    The end date; uses “now” if nil

    interpreter

    The interpreter to use; uses a fresh instance of CoreMotionStandardActivityInterpreter if nil

    callback

    The callback to call when all activities are retrieved and the interpreter has run