Flutter
Last updated
Was this helpful?
Last updated
Was this helpful?
Install the terra-react
package using npm (flutter pub add terra_flutter_bridge
), and follow the respective guides below based on the platforms you want to access
Using XCode, open the .xcodeproj
for the app in the /ios
directory of your project
RunsetUpBackgroundDelivery
in your AppDelegate's didFinishLaunchingWithOptions
function
This will ensure you get updates for the user's Apple Health data automatically sent to your destination.
Data will
still be sent even if your app is exited/killed completely
only be sent if the device is unlocked
Follow the instructions below within the /android
directory of your project
First, initialize the TerraManager
class at the top level of the app.
Terra
initializationTerra
should be initialized every time your app is opened.
This is a necessary prerequisite for other SDK functions to run as expected
Terra
is thereafter ready to be used with other functions
Once Terra is initialized, you can create a connection.
Run the initConnection
function with Connections.APPLE
or Connections.SAMSUNG
to have the Apple Health or Health Connect permission screen pop up.
initConnection
only needs to be run a single time. Apple Health & Health Connect prohibit the permission popup to appear more than once for any given permission, so calling initConnection
more than once will result in no action at all
The only case where it would re-appear is if:
you call initConnection with an expanded set of customPermissions
the app is deleted & reinstalled.
🚧 Webviews & HealthKit permissions screen
HealthKit implements the permissions popup as a webview
If your app is also based on a webview, you will need to interrupt your webview, call initConnection
, then upon completion re-open your webview
To ensure a connection is still valid on the client side, use the getUserId
method. This function is synchronous and returns the user_id
right away or null if none exists.
Always use this method right after initializing Terra to see if the connection still exists,
if the connection exists, all is good! 🎉 keep vibing along
In order to disconnect an Apple Health user, you may use the same endpoint as for Web API-based integrations, called from your backend
You may set toWebhook
to false if you wish for the callback function to return the data payload on the client side.
Check out the Flutter SDK reference for details about all the functions in the SDK
Planned Workouts are only available for APPLE, and on iOS 17 and above
Writing planned workouts allows you to create a workout plan for the user (such as those commonly used with Zwift)
This will typically look like the following example:
Planned workouts consist of a series of steps. Each step has:
Completion criteria (called duration for all intents and purposes). For example:
distance (keep going until you cover 500m),
energy expenditure (keep going until you burn 200 kcal)
heart rate threshold (keep going until your heart rate reaches above 150 bpm)
etc..
A target to be maintained
heart rate (maintain heart rate between certain bounds)
speed (maintain speed between certain bounds)
grade (inclination above a certain threshold)
etc...
An associated intensity label
Warmup
Active
Cooldown
etc..
An exercise type
Running
Cycling
Deadlifting
etc...
A series of sub-steps
These modalities allow any workout to be described in a series of defined steps for each of its segments.
Once written, a planned workout will be available in the user's Workout app on their Apple Watch. They will then be able to follow the workout and receive guidance throughout each step.
In order to write a workout for the user to follow on their Apple Watch, use the postPlannedWorkout function as below, with the instance of terra you created above
To do this, run the as below:
customPermissions
is used to customize the permissions list shown in the Apple Health/Health Connect popup when calling . When empty, it defaults to all available permissions
if you expect the connection to exist, but returns null, call initConnection to re-establish it. No permission screen will be shown again and the user flow will be unaffected
if it is expected for the connection to no longer exist, you may allow the user to re-connect Apple Health if they so choose (you'd then call as before, but no permission screen would be shown)
You can request for historical data using one of the
Add https://github.com/tryterra/TerraiOS
as a package dependency
Add Capabilities:
Healthkit > Healthkit Background Delivery
Background Modes > Background processing
Background modes > Background fetch
In your info.plist, add:
Privacy - Health Share Usage Description
: custom text shown in the Apple Health permission screen
Permitted background task scheduler
: co.tryterra.data.post.request
token
is a single-use token created to ensure the authentication endpoint for creating a (and connecting the SDK to Terra's servers) does not get abused.
In order to generate it, place the call below on your server, and provide it to your client side using your own logic.
During the development phase, it it acceptable to place this call on the client side, exposing your API key in your mobile app.
For a production implementation, DO NOT expose your API key this way, and make sure to only make this call from your backend
If you need to access Terra's Health & Fitness API, it is only secure to do so from your server backend and send the desired data to your mobile frontend.
Never expose your API key on the client side unless you are simply testing
Creates a token to be used with initConnection() functions in the Terra mobile SDKs in order to create a user record for Apple Health or Samsung Health (or equivalent)
/auth/generateAuthToken
your developer ID
testingTerra
your API key
OtHJok60oQmT8zhnUWc4SWBJI7ztPTs88C0gOsJJ