Background Delivery
Background delivery ensures that data updates are sent to your backend via webhooks, even when the application is in the background or closed.
iOS
Important notes about background delivery on iOS
- For most data types the most possible frequency of updates is 1 hour.
- iOS can update data more frequently for some data types, for example, vo2 max.
- iOS may throttle the frequency of updates for background delivery depending on the app’s activity, battery state, etc.
- Background delivery is not possible while device is locked, so it will be executed only when the device is unlocked.
- iOS may stop background delivery if it detects that the app is not active for a long time.
- The feature is available starting with iOS 15.
Setup
Enable background delivery for app target
- Open XCode with your ios project
- Open the folder of your project in Xcode
- Select the project name in the left sidebar
- Open Signing & Capabilities section
- Select HealthKit background delivery under HealthKit section
Initialization at app startup
For background delivery to work properly, you need to initialize the SpikeSDK at app startup.
AppDelegate.swift
:
or AppDelegate.mm
:
Android
Important notes about background delivery on Android
- Background delivery is scheduled to run every hour. But ultimately Android decides when the delivery will be executed.
- Android may throttle the frequency of updates for background delivery depending on the app’s activity, battery state, etc.
- Android may stop background delivery if it detects that the app is not active for a long time.
- There is a limit of queries that can be done in Health Connect and it is different for foreground and background reads, so please request only essential data to be delivered in background. More information on (Health Connect documentation)
Setup
Add the following permission to your AndroidManifest.xml:
React Native specific
Add includeBackgroundDelivery: true
when asking for permissions:
You can also ask for background delivery permission at the same time as other permissions.
Now you can enable background delivery:
Keep in mind that calling enableBackgroundDelivery()
will overwrite previous configuration. So you have to call it with all the data types you want in one call.
To check current configuration call getBackgroundDeliveryConfig()
method.
To stop background delivery call disableBackgroundDelivery()
method.