https://github.com/kitasuke/cardio
Simple HealthKit wrapper for workout in watchOS 2
https://github.com/kitasuke/cardio
Last synced: about 1 year ago
JSON representation
Simple HealthKit wrapper for workout in watchOS 2
- Host: GitHub
- URL: https://github.com/kitasuke/cardio
- Owner: kitasuke
- License: mit
- Created: 2015-10-04T15:03:50.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-11-30T05:50:13.000Z (over 9 years ago)
- Last Synced: 2023-10-20T21:00:50.712Z (over 2 years ago)
- Language: Swift
- Homepage:
- Size: 87.9 KB
- Stars: 81
- Watchers: 6
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/kitasuke/Cardio)
# 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
```swift
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
```swift
let cardio = try? Cardio(context: context)
```
- Authorize HealthKit to access
```swift
if !cardio.isAuthorized {
cardio.authorize { result in
}
}
```
- Set update handler
```swift
cardio.distanceHandler = { distance, total in
}
cardio.activeEnergyHandler = { activeEnergy, total in
}
cardio.heartRateHandler = { heartRate, average in
}
```
- Start your workout session
```swift
cardio.start { result in
}
```
- End your workout session
```swift
cardio.end { result in
}
```
- Pause your workout
```swift
cardio.pause()
```
- Resume your workout
```swift
cardio.resume()
```
- Save your workout in HealthKit
```swift
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](https://github.com/Carthage/Carthage).
To install Cardio into your Xcode project using Carthage, specify it in your Cartfile:
```ruby
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
```ruby
$ 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](https://github.com/kitasuke/Cardio/blob/master/LICENSE) file for more info.