React Native
Spike React Native SDK is a library on top of HealthKit that 1) helps with the extraction of data. 2) pushes data to SpikeAPI and delivers standardized data.
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 pods afterward.
iOS 13.0+
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
- Allow Clinical Health Records and Background Delivery if needed.
Add Health Kit permissions descriptions to your ios/<Project Name>/Info.plist file.
Import SpikeSDK
Add Spike initialization code to App.tsx file outside the App component.
Use useSpikeEvents hook to handle results from SpikeSDK.
Provide SpikeSDK with client id, authorization token, user id and optionally postback (webhook) URL.
Check for current session Promise<string | undefined>:
Remove session data:
Get data for specified Spike Data types.
or
All available Data types SpikeDataType or use all of the instantly SpikeDataTypesAll: DataTypeStep DataTypeHeartRate DataTypeRestingHeartRate DataTypeActiveEnergy DataTypeBasalEnergy DataTypeAppleMoveTime DataTypeAppleExerciseTime DataTypeDistanceWalkingRunning DataTypeFloors DataTypeWorkout DataTypeSleepAnalysis
Getting DataTypeWorkout data will return results through the onWorkoutDataResult and onWorkoutDataFailure callbacks of useSpikeEvents hook.
Getting DataTypeSleepAnalysis data will return results through the onSleepAnalysisDataResult and onSleepAnalysisDataFailure callbacks of useSpikeEvents hook.
Call the function getDataInRange with the preferred date range to get historical data.
Example: To get data for the first 7 days of January 2023:
With enabled debug mode SpikeSDK will print performed actions. You can see logs directly running the application from Xcode. Use logs filter [SpikeSDK]. It is better to call this before calling Spike.initialize();.
Allow update data for specified Spike Data types and send it to Spike.
Go to your target's Signing & Capabilities section and add Background Modes. Allow Background fetch. And check Info.plist for UIBackgroundModes.