SpikeSDK React Native (v3)
iOS 13.0+ Android 9.0+ (Level 28, P, Pie)
Install the react-native-spike-sdk package from npm:
Use pod install and pod update commands from ios/ folder of your app to install/update SpikeSDK.
To add HealthKit support to your application's Capabilities.
- Open the iOS/ folder of your project in Xcode
- Select the project name in the left sidebar
- Open Signing & Capabilities section
- In the main view select '+ Capability' and double click HealthKit
More details you can find here.
Add Health Kit permissions descriptions to your Info.plist file:
To add the SDK to your Android project, you have to add the following to your project's build.gradle file in the repositories block.
Include the necessary health permissions in your AndroidManifest.xml to fully leverage the Spike SDK and access data from apps integrated with Health Connect. Please refer to this guide for details on the required permissions.
Note: Only request permissions essential to your app’s functionality. Requesting unused permissions may lead to app store rejections.
Add an intent filter to your activity definition so that you can request the permissions at runtime.
To handle Android 14 you also need to add activity-alias to your AndroidManifest.xml It is just a wrapper for the activity that requests permissions so no real activity is necessary.
To set up the Spike SDK create SpikeConnectionV3 instance with your Spike application id, auth token and user id unique to each of your users:
If you plan to use Android Health Connect and/or Apple HealthKit data providers you should first get users permission to use their data:
- for Android there are more methods that let you get permissions granted by user, check if Health Connect is installed or should be updated, etc. If you are OK with SpikeSDK handling these, you can use requestHealthPermissions only. On iOS requestHealthPermissions is the only method that has to be called. Keep in mind, that you should do it before trying to read data from Android Health Connect or Apple HealthKit.
Info: The maximum permitted date range is 90 days There are two types of data you can retrieve from Spike:
- Records consist of the raw data points collected from user devices or applications.
- Statistics, on the other hand, are calculated values derived from records.
Now you can read hourly statistics data of steps and distance for today:
where:
Background delivery ensures that data updates are sent to your backend via webhooks, even when the application is in the background or closed.
- 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.
Important: The SpikeSDK, along with any other HealthKit applications, cannot guarantee data synchronization on a fixed schedule. The hourly sync interval serves as a guideline rather than a strict requirement enforced by iOS. Consequently, the actual synchronization frequency may vary, occurring hourly, once per day, or during specific system-defined events, such as the conclusion of Sleep Mode or when the device begins charging.
- 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
You can skip this step if you are using Expo.
For background delivery to work properly, you need to initialize the SpikeSDK at app startup.
AppDelegate.swift:
or AppDelegate.mm:
- 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)
The SpikeSDK, along with any other applications, cannot guarantee data synchronization on a fixed schedule. The hourly sync interval serves as a guideline rather than a strict requirement enforced by Android. Consequently, the actual synchronization frequency may vary, occurring hourly, once per day, or during specific system-defined events, such as the conclusion of Sleep Mode or when the device begins charging.
Add the following permission to your AndroidManifest.xml:
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.