Integration with APPLE HealthKit is now possible through our Apple SDK (.xcframework) called 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
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:
This set can then be passed as the parameter readTypes when initiating the Terra Client as shown below.
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:
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:
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.
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:
The following function will push athlete data to your webhook URL. (No parameters required)
To deauthorize a user, please follow our Deauthentication Endpoint on the Docs. In addition to this, please also set the client instance to nil: