Cardio icon indicating copy to clipboard operation
Cardio copied to clipboard

Simple HealthKit wrapper for workout in watchOS 2

Carthage compatible

Cardio

Simple HealthKit wrapper for workout in watchOS 3

How it works in demo project

Features

  • Super simple to access HealthKit
  • Cuztomizable preferences
  • Well-designed for workout app
  • Easy way to save workout data in HealthKit

Usage

  • Extend Context protocol and set your favorite types
public protocol Context {
    var activityType: HKWorkoutActivityType { get }
    var locationType: HKWorkoutSessionLocationType { get }

    var distanceUnit: HKUnit { get }
    var activeEnergyUnit: HKUnit { get }
    var heartRateUnit: HKUnit { get }

    var distanceType: HKQuantityType { get }
    var activeEnergyType: HKQuantityType { get }
    var heartRateType: HKQuantityType { get }

    var shareIdentifiers: [String] { get }
    var readIdentifiers: [String] { get }
}
  • Initialize Cardio with context
let cardio = try? Cardio(context: context)
  • Authorize HealthKit to access
if !cardio.isAuthorized {
    cardio.authorize { result in
    }
}
  • Set update handler
cardio.distanceHandler = { distance, total in
}

cardio.activeEnergyHandler = { activeEnergy, total in
}

cardio.heartRateHandler = { heartRate, average in
}
  • Start your workout session
cardio.start { result in
}
  • End your workout session
cardio.end { result in
}
  • Pause your workout
cardio.pause()
  • Resume your workout
cardio.resume()
  • Save your workout in HealthKit
cardio.save { result in
}

See more detail in Demo project

Requirements

watchOS 3.0+
Swift 3.0+

Installation

Add HealthKit entitlement in Capabilities tab for your both containing app target and WatchKit extension target

Carthage

Cardio is available through Carthage.

To install Cardio into your Xcode project using Carthage, specify it in your Cartfile:

github "kitasuke/Cardio"

Then, run carthage update

You can see Cardio.framework and Result.framework in Carthage/Build/iOs and Carthage/Build/watchOS/ now, so drag and drop them to Embedded Binaries in General menu tab for your iOS app and WatchKit Extension.

In case you haven't installed Carthage yet, run the following command

$ brew update
$ brew install carthage

Manual

Copy all the files in Cardio and Carthage/Checkouts/Result/Result directory into your WatchKit Extension.

License

Cardio is available under the MIT license. See the LICENSE file for more info.