Apple SDK

Integration with APPLE HealthKit is now possible through our Apple SDK (.xcframework) called TerraSwift:

TerraSwift

This library allows developers to connect to TERRA through Swift (implemented with Swift5.0). This library uses HealthKit for iOS v13+. It thus would not work on iPad or MacOS or any platform that does not support Apple HealthKit. (Must have signing capabilities for Healthkit)

The package must be added as a dependency to your project. This can be done simply by editting your App's dependencies and adding TerraSwift as a dependency with the following location: https://github.com/tryterra/TerraSwift.git.

You may now import the package using: import TerraSwift

Permissions

As default, we have enabled all our required healthkit HKObjectTypes for the functionality of the whole package. However if there are healthkit parameters for which you do not wish to be included, you may input a custom set of HKObjectTypes as a subset of the following:

  • Workouts
  • Activity Summary
  • Active Energy Burnt
  • Step Count
  • Heart Rate
  • Heart Rate Variability in SDNN
  • Vo2Max
  • Height
  • Apple Exercise Time
  • Body Mass
  • Flights Climbed
  • Body Mass Index
  • Body Fat Percentage
  • Distance Swimming
  • Distance Cycling
  • Distance Walking/Running
  • Biological Sex
  • Date of Birth
  • Basal Energy Burned
  • Swimming Stroke Count
  • Resting Heart Rate
  • Blood Pressure Diastolic
  • Blood Pressure Systolic
  • Body Temperature
  • Lean Body Mass
  • Oxygen Saturation
  • Sleep Analysis
  • Respiratory Rate
  • Workout Route

This set can then be passed as the parameter readTypes when initiating the Terra Client as shown below.

Usage

Start by connecting to Terra through our API as documented here. To make this easier, there is a function provided by this package which allows your users to connect with Terra. By simply giving us your dev-id and X-API-Key that we provide for you when you sign up with us, you can register a user by simply running this function:

Swift

This will return a userId for which you may now use to acquire data with.

Using this user ID, you may now create a Terra Client as such:

Swift

Upon initializing, the Client will automatically push workout details of the user to your callback url everytime they open your application. It will also automatically push Daily, Sleep, and Body Data to your callback url every 8 hours. However this can only occur when the user enters your application. This feature is controlled by the auto parameter. By default, it is set to true. However if you wish to make other timed requests, you may create your own timer and use the functions described below while setting auto to false.

Requests

You may also request for specific data from specific days using the built in functions.

The following functions will push data to your webhook URL from between the given startDate and endDate parameters:

Body Data

Swift

Daily Data

Swift

Sleep Data

Swift

Activity Data

Swift

The following function will push athlete data to your webhook URL. (No parameters required)

For Athlete Data

Swift

Deauthorize

To deauthorize a user, please follow our Deauthentication Endpoint on the Docs. In addition to this, please also set the client instance to nil:

Swift