Usage: Sync health data manually
Sync Apple Health data by yourself.
The automatic implementation is faster and easier to integrate and is what most developers need, try to use it before attempting to create a custom sync process.
Sync health data manually
There are 2 types of health data Summaries and Events.
Health Data | Timezone | Oldest date of retrieval | Latest date of retrieval | Class |
---|---|---|---|---|
Summary | UTC | N/A | Yesterday | AHRookSyncManager |
Event | UTC | N/A | Today | AHRookSyncManager |
Sync summaries
Use sync(bool enableLogs)
to sync the last 29 days of SLEEP_SUMMARY, PHYSICAL_SUMMARY and BODY_SUMMARY (not
including today).
If the app goes to the background the synchronization will fail, use scheduleYesterdaySync. instead if you want the synchronization to continue until it finishes (scheduleYesterdaySync will not only sync summaries, but also events).
void syncSummariesHistoric() async {
try {
await AHRookSyncManager.sync(enableLogs: isDebug);
// Historic summaries sync started
} catch (error) {
// Handle error
}
}
Use sync(DateTime date)
to sync SLEEP_SUMMARY, PHYSICAL_SUMMARY and BODY_SUMMARY for the provided date
.
void syncSummaries() async {
try {
await AHRookSyncManager.sync(date: date);
// Summaries synced successfully
} catch (error) {
// Handle error
}
}
Use sync(DateTime date, AHSummarySyncType summary)
to sync the summary
of choice for the provided date
.
void syncSingleSummary() async {
try {
await AHRookSyncManager.sync(date: date, summary: summarySyncType);
// Summary synced successfully
} catch (error) {
// Handle error
}
}
Sync events
Use syncEvents(DateTime date, AHEventSyncType event)
to sync the event
of choice for the provided date
.
void syncSingleEvent() async {
try {
await AHRookSyncManager.syncEvents(date, eventSyncType);
// Event synced successfully
} catch (error) {
// Handle error
}
}
Sync current day events
Current day events allow to send small amounts of health data, but they also return the data that was sent, you can use this data to update your UI without waiting for the webhook event.
Steps events
Retrieve and upload current day steps count of Apple Health.
void syncStepsEvents() async {
try {
final steps = await AHRookSyncManager.getTodayStepsCount();
if (steps != null) {
// Update the UI with steps count
} else {
// No steps events found
}
} catch (error) {
// Handle error
}
}
Calories events
Retrieve and upload current day calories count of Apple Health.
void syncCaloriesEvents() async {
try {
final calories = await AHRookSyncManager.getTodayCaloriesCount();
if (calories != null) {
// Update the UI with calories count
} else {
// No calories events found
}
} catch (error) {
// Handle error
}
}