Q: How to access Apple Data with Flutter?
LinearGoat2 months ago
How can I retrieve data from Apple watch to my flutter app?
Elliottadmin2 months ago
Hey there!
In order to access data through our Apple integration, you can use our native iOS SDK, or cross-platform Flutter or React Native solutions.
To start developing using the SDK with Flutter, you will have to run the following sequence of functions (or the equivalent in other SDKs):
Future<String> getAuthToken() async { var response = await http.get(Uri.parse("$yourApiBackend/authToken")); if (response.statusCode == 200) { var data = jsonDecode(response.body); return data["token"]; } return ""; }
TerraFlutter.initTerra("YOUR-DEV-ID", "YOUR-USER-ID").then((value) async { log("Init Status => ${value?.success} ${value?.error}"); var token = await getAuthToken(); await TerraFlutter.initConnection(Connection.appleHealth, token, true, []).then((value) async { log("Connect Status => ${value?.success} ${value?.error}"); }); // fetches historical data await TerraFlutter.getNutrition(Connection.appleHealth, DateTime(2023, 10, 01), DateTime(2023, 10, 10), toWebhook: true).then((value) async { log("Get Payload Status => ${value?.success} ${value?.error}"); }); });
Hope this has clarified things :)
LinearGoat2 months ago
Thanks!