spike_flutter_sdk 0.0.1
spike_flutter_sdk: ^0.0.1 copied to clipboard
Reads HealthKit data from iOS HealthKit, and allows you to sync it with your chosen backend.
HealthKit API allows you to read the Apple HealthKit data (based on another package - https://pub.dev/packages/health_kit_reporter ). Then, it allows you to send the data to your backend chosen.
Features #
- Read the Apple HealthKit data.
- Send this data to backend.
- Register periodic background tasks to send and read the data.
Getting started #
Setup everything like you would to with https://pub.dev/packages/health_kit_reporter . Then, use this library as shown in example below (or in the longer one).
Usage #
/*
* 1. Initialization
*/
// Your API credentials
const _authToken = 'fa0b3803-6068-4ea7-9788-eccce210d30c';
const _clientId = 'ea9e03f5-be45-49fb-bf4c-47a88c184c3b';
const _host = 'https://api.spikeapi.com';
const _callbackUrl = ''; // Configurable by the client.
const _userId = 'jasbdhasbfashfj';
// Origin of the endpoint you are going to sync the data with
const _origin = Origin(
host: _host,
userId: _userId,
);
// API to read the data from Apple HealthKit
final _reporting = HealthKitReporting();
const _api = SpikeApi(origin: _origin);
/*
* 2. Requesting authorization.
*/
await _reporting.requestReadAuthorization();
/*
* 3. Initializing user integration.
*/
final integrationResult = await _api.initIntegration(
authToken: _authToken,
clientId: _clientId,
);
/*
* 4. Reading Apple HealthKit data
*/
final appleData = await _reporting.readActivitiesSummaryData(
from: DateTime(2022, 09, 22),
to: DateTime.now(),
);
/*
* 5. Sending Apple HealthKit data to your backend.
*/
await _api.sendData(
authToken: _authToken,
request: DataRequest(
records: appleData,
userId: integrationResult.userId,
callBackUrl: _callbackUrl,
),
);
/*
* 6. Registering SpikeTaskRunner as a way to send data to backend periodically.
*/
const runner = SpikeTaskRunner();
runner.registerTask({
origin: _origin,
clientId: _clientId,
authToken: _authToken,
callbackUrl: _callbackUrl,
});
copied to clipboard
Additional information #
All information is here and in the GitLub page of this package.