For the complete documentation index, see llms.txt. This page is also available as Markdown.

Apple Health, Health Connect & Samsung Health

Once a user connects Apple Health, Health Connect, or Samsung Health, the Thryve SDK can retrieve and sync data from these native sources either automatically or manually.

We generally recommend manually synchronizing connected native data sources whenever your app comes to the foreground to ensure all data is up-to-date, as automatic background data synchronization is highly dependent on the operating system and its resource and battery management, allowing for regular synchronizations.

Web data sources are seamlessly managed by the Thryve backend. This page is only related to data sources where health data is directly retrieved from the end user device via the Thryve SDK.

SDK Module Configuration

When using Apple Health, Health Connect & Samsung Health, you will need the optional SDK modules Apple Health, Health Connect or Samsung Health. Make sure to initialize the corresponding configurations ThryveAppleHealthConfig, ThryveHealthConnectConfig and ThryveSamsungHealthConfig for correct functionality.

Parameter
Description
Mandatory

configs

List of ThryveSDKModulesConfig for imported SDK modules.

yes

When using the Apple Health module, make sure to define the data types in the ThryveAppleHealthConfig . This is only relevant for iOS integration.

Parameter
Description
Mandatory

dataTypes

The Apple Health data types Set<ThryveAppleHealthDataType> required by your app. Ensure to limit types to data described in your data privacy policy. Always ensure the configured dataTypes are consistent across your application. Please refer to this document to understand the data types.

yes

enableBackgroundSync

Configures background data synchronization on SDK initialization (retrieving data when your app is closed or idle). Requires Background Delivery to be enabled for the HealthKit Capability.

no

When using the Health Connect module, make sure to define the data types in the ThryveHealthConnectConnectorConfig . This is only relevant for Android integration

Parameter
Description
Mandatory

dataTypes

Health Connect data types required by your app. Ensure to limit types to data described in your data privacy policy. Always ensure the configured dataTypes are consistent across your application. Please refer to this document to understand the data types.

no, defaults to all supported data types

enableBackgroundSync

Will request background data sync permissions. If permissions are granted, background tasks using WorkManager will be scheduled by the Thryve SDK.

no, defaults to true

enableReadHealthDataHistory

Will request historical data sync permissions. If permissions are granted, timeframes older than 30 days can be requested when using manual data synchronization methods.

no, defaults to true

When using the Samsung Health module, make sure to define the data types in the ThryveSamsungHealthConfig . This is only relevant for Android integration

Parameter
Description
Mandatory

dataTypes

The Samsung Health data types required by your app. Please refer to this document to understand the data types. Ensure to limit types to data described in your data privacy policy. Always ensure the configured dataTypes are consistent across your application.

no, defaults to all supported data types

enableBackgroundSync

Schedules background tasks using WorkManager for data synchronization when app is closed or idle.

no, defaults to true

Automatic Background Data Synchronization

We utilize different technologies for automatic background data retrieval on iOS and Android. On iOS, the Thryve SDK employs HealthKit’s native background synchronization API. For Android, synchronization is scheduled and managed via WorkManager.

The availability of background data synchronizations is configurable for Apple Health, Samsung Health and Health Connect data sources in the corresponding config objects.

The ThryveHealthConnect and ThryveSamsungHealth modules perform background synchronization every 30 minutes once enableBackgroundSync is enabled in the configuration.

ThryveAppleHealth, on the other hand, triggers background synchronization whenever new data becomes available in Apple Health while the app is running in the background.

Background data synchronization is enabled in ThryveAppleHealthConfig, like on the other native data sources.

let appleHealthConfig = ThryveAppleHealthConfig(
    dataTypes: ThryveAppleHealthDataType.allConnectorTypes,
    enableBackgroundSync: true
)

The Thryve SDK then registers for HealthKit background delivery on your behalf, and syncs whenever Apple Health records new data while your app is in the background. Pass the config when you initialize the SDK, in didFinishLaunchingWithOptions. Apple requires an app to register for background delivery within the first seconds after launch, so initializing the SDK later means updates are missed until the next launch.

To enable background data synchronization (retrieving data when your app is closed or idle) in native Android, using Kotlin, enable background sync in the ThryveHealthConnectConfig .

val healthConnectConfig = ThryveHealthConnectConfig(
        dataTypes = ThryveHealthConnectDataType.entries.toList(),
        enableBackgroundSync = true,
        enableReadHealthDataHistory = true
    ) 

To enable background data synchronization (retrieving data when your app is closed or idle) in native Android, using Kotlin, enable background sync in the ThryveSamsungHealthConfig .

val samsungHealthConfig = ThryveSamsungHealthConfig(
        dataTypes = ThryveSamsungHealthDataType.entries.toList(),
        enableBackgroundSync = true
    )

In React Native, using javascript or Typescript, enable enableBackgroundSync sync in your configuration

The background data sychronization in the Flutter SDK is enabled in the ThryveSDKConfig during initialization. Check the Flutter SDK initialization section

Manual Data Synchronization

Manual data synchronization is recommended to ensure all recent data is available when the user opens your app. Therefore, we recommend using synchronize whenever your app moves to the foreground.

synchronize will ensure that both epoch and daily data added since the last data synchronization will be fetched from Apple Health, Health Connect, or Samsung Health. The initial execution of synchronize will fetch all data for today.

The manual data retrieval methods will return a ThryveResponse. This response will be true if the data is uploaded successfully. If issues occur during retrieval or upload, the response will be false, and a list of ThryveError will be provided. Each ThryveError contains details about the error encountered.

Only one instance of each method (synchronize, backfillDaily, and backfillEpoch) can run at a time for a given data source. If another call to the same method is made while the previous call is still running, the new call fails immediately with error code 10010, while the existing call continues unaffected. Wait for the running call to complete before invoking the same method again.

Historic data backfill

To access data predating the initial synchronization, the Thryve SDK provides methods for backfilling historical data. These methods allow synchronization of epoch and daily data within a specified timeframe.

backfillEpoch fetches epoch data for the given timeframe, with a maximum of 30 days. If the difference between startDate and endDate is more than 30 days, the SDK will count from the end date 30 days back

backfillDaily fetches daily data for the given timeframe, with a maximum of 365 days. If the difference between startDate and endDate is more than 365 days, the SDK will count from the end date 365 days back

Parameter
Description
Mandatory

dataSource

The data source to synchronize data from. iOS defaults to .apple

yes, on Android. no, on iOS

dataTypes

The data types to synchronize. It defaults to the data types defined in the data source config.

no

startDate

The date to start data retrieval and synchronization from. It is applicable only to the backfiill functions

yes

endDate

The date to end data retrieval and synchronization on. It defaults to today and applicable only to the backfiill functions.

no

The manual data retrieval methods will return a ThryveResponse. This response will be true if the data is uploaded successfully. If issues occur during retrieval or upload, the response will be false, and a list of ThryveError will be provided. Each ThryveError contains details about the error encountered.

Last updated