React Native
Last updated
Was this helpful?
Last updated
Was this helpful?
Install the terra-react
package using npm (npm install terra-react
), 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
To do this, run the Terra manager initialization function as below:
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 checkAuth
method.
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
You may set toWebhook
to false if you wish for the callback function to return the data payload on the client side.
You may write data into Apple Health (Health Connect not yet supported) through one of the helper functions in the SDK
device_data
must be passed in for postActivity to succeed.
postActivity
uses the HKWorkout class internally, which has been deprecated as of iOS 17.
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 false
, 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)
In order to disconnect an Apple Health user, you may use, called from your backend
You can request for historical data using one of the
Check out the for details about all the functions in the SDK
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
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
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
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