Q: How to get Apple HealthKit data with the Terra iOS SDK
CostlyQuail1 month ago
How do I get started with the TerraManager
in the iOS sdk. We have already followed the guide on enabling HealthKit permissions but the flow does not make sense to me
Chandruadmin1 month ago
Hi there.
After following the guide on setting up the dependencies for the iOS sdk, the flow would look something like this:
var terra: TerraManager Terra.instance(devId: "<YOUR-DEV-ID>", referenceId: "<YOUR-INTERNAL-USER-ID>") { manager, error in if error == nil { terra = manager } }
@app.get('/terra/sdktoken') def get_terra_sdk_token(): # perform auth for your user if required headers = { "dev-id": "<YOUR-DEV-ID>", "x-api-key": "<YOUR-API-KEY>" } response = requests.post("https://api.tryterra.co/v2/auth/generateAuthToken", headers=headers) data = response.json() return { 'token': data['token'] }
And then request this endpoint from your app and use the token
terra.initConnection(type: .APPLE, token: token, customReadTypes: [], schedulerOn: true) { success, error in if !success { print("Failed to initialise connection") } }
terra.getDaily(type: .APPLE, startDate: Date, endDate: Date, toWebhook: true)