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). Default state is true which requires Background Delivery to be enabled for a HealthKit Capability.

Alternatively, use the executeBackgroundSync method in AppDelegate

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 Healtsh, 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.

To enable background data synchronization (retrieving data when your app is closed or idle), use the executeBackgroundSync method within the didFinishLaunchingWithOptions function in AppDelegate right after connecting to Apple Health.

Apple mandates that this logic runs within the first few seconds of app startup for data delivery, hence its placement in AppDelegate. Refer to the sample code for further details.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // When Apple's Health app initiates contact, it triggers your application 
        // via didFinishLaunchingWithOptions. Once activated, HealthKit waits 
        // briefly to determine if your app wishes to renew its query contracts. 
        // Calling the relevant method as early as possible renews these contracts, 
        // enabling the app to fetch new data promptly from Apple Health.
        ThryveSDK.get().executeBackgroundSync(
                  dataSource: .apple,
                  dataTypes: ThryveAppleHealthDataType.allTypes)
        // Override point for customization after application launch.
        return 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 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 .

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 durint 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.

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