Mobile SDKs
SpikeSDK React Native
current react native sdk version 4 2 63 react native package can be found here example app can be found here requirements ios 13 0+ android 9 0+ (level 28, p, pie) sdk installation install the react native spike sdk package from npm https //www npmjs com/package/react native spike sdk yarn add react native spike sdk ios setup guide use pod install and pod update commands from ios/ folder of your app to install/update spikesdk ios signing & capabilities 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 https //developer apple com/documentation/healthkit/setting up healthkit info plist add health kit permissions descriptions to your info plist file info plist \<key>nshealthshareusagedescription\</key> \<string>we will use your health information to better track workouts \</string> \<key>nshealthupdateusagedescription\</key> \<string>we will update your health information to better track workouts \</string> android setup 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 build gradle allprojects { repositories { // other repositories maven { url 'https //gitlab com/api/v4/projects/43396247/packages/maven' } } } android permissions 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 https //developer android com/health and fitness/guides/health connect/get started#declare permissions 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 \<uses permission android\ name="android permission health read nutrition"/> \<uses permission android\ name="android permission health read active calories burned"/> \<uses permission android\ name="android permission health read total calories burned"/> \<uses permission android\ name="android permission health read steps"/> \<uses permission android\ name="android permission health read distance"/> \<uses permission android\ name="android permission health read elevation gained"/> \<uses permission android\ name="android permission health read resting heart rate"/> \<uses permission android\ name="android permission health read heart rate variability"/> \<uses permission android\ name="android permission health read floors climbed"/> \<uses permission android\ name="android permission health read basal metabolic rate"/> \<uses permission android\ name="android permission health read sleep"/> \<uses permission android\ name="android permission health read heart rate"/> \<uses permission android\ name="android permission health read exercise"/> \<uses permission android\ name="android permission health read speed"/> \<uses permission android\ name="android permission health read power"/> \<uses permission android\ name="android permission health read oxygen saturation"/> \<uses permission android\ name="android permission health read blood glucose"/> \<uses permission android\ name="android permission health read respiratory rate"/> \<uses permission android\ name="android permission health read weight"/> \<uses permission android\ name="android permission health read height"/> \<uses permission android\ name="android permission health read body fat"/> \<uses permission android\ name="android permission health read lean body mass"/> \<uses permission android\ name="android permission health read body water mass"/> \<uses permission android\ name="android permission health read body temperature"/> \<uses permission android\ name="android permission health read blood pressure"/> \<uses permission android\ name="android permission health read bone mass"/> add an intent filter to your activity definition so that you can request the permissions at runtime \<intent filter> \<action android\ name="androidx health action show permissions rationale" /> \</intent filter> 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 \<activity alias android\ name="viewpermissionusageactivity" android\ exported="true" android\ targetactivity=" mainactivity" android\ permission="android permission start view permission usage"> \<intent filter> \<action android\ name="android intent action view permission usage" /> \<category android\ name="android intent category health permissions" /> \</intent filter> \</activity alias> spike sdk usage step 1 create spike connection 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 import spike from 'react native spike sdk'; const connection = await spike createconnectionapiv3( "applicationid", "signature", "enduserid" ); step 2 ask user for permissions if you plan to use android health connect and/or apple healthkit data providers you should first get users permission to use their data // this call may present user with os native modal asking for read // permissions needed to get steps and distance data if you want to // present it only once, you should list all the statistic types you // plan to use otherwise, you can call this only before you actually // want to use the data await spikeconnection requesthealthpermissions({ statistictypes \[statisticstype steps, statisticstype distancetotal] }); 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 step 3 get data 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 statistics now you can read hourly statistics data of steps and distance for today const now = new date(); const start = new date(now\ getfullyear(), now\ getmonth(), now\ getdate() 1); const end = new date(now\ getfullyear(), now\ getmonth(), now\ getdate() + 1); const statistics = await spikeconnection getstatistics( \[statisticstype steps, statisticstype distancetotal], start, end, statisticsinterval hour, new statisticsfilter(false, \[provider apple, provider healthconnect]) ) where enum statisticstype { steps = "steps", distancetotal = "distance total", distancewalking = "distance walking", distancecycling = "distance cycling", distancerunning = "distance running", caloriesburnedtotal = "calories burned total", caloriesburnedbasal = "calories burned basal", caloriesburnedactive = "calories burned active", } enum statisticsinterval { day, hour } // filter export class statisticsfilter { excludemanual boolean = false providers provider\[] | undefined constructor({ excludemanual = false, providers = undefined } statisticsfilterconstructorparameters) { this excludemanual = excludemanual; this providers = providers; } } // result interface statistic { start string; end string; duration number; type statisticstype; value number; unit unit; rowcount number | null; recordids uuid\[] | null; } records const now = new date(); const start = new date(now\ getfullyear(), now\ getmonth(), now\ getdate() 1); const end = new date(now\ getfullyear(), now\ getmonth(), now\ getdate() + 1); const records = await spikeconnection getrecords({ oftypes metrictypes, from start, to end, filter new statisticsfilter({ excludemanual false, providers \[provider apple, provider healthconnect] }) }) enum metrictype { caloriesburnedactive = "calories burned active", caloriesburnedbasal = "calories burned basal", caloriesburned = "calories burned", distancetotal = "distance", distancewalking = "distance walking", distancecycling = "distance cycling", distancerunning = "distance running", distancewheelchair = "distance wheelchair", distanceswimming = "distance swimming", stepstotal = "steps", } // result interface spikerecord { recordid uuid; inputmethod inputmethod | null; startat string; endat string | null; modifiedat string; duration number | null; provider provider | null; providersource providersource | null; issourceaggregated boolean | null; source recordsource | null; metrics { \[key string] number } | null; activitytags activitytag\[] | null; activitytype activitytype | null; sessions activityentry\[] | null; laps activityentry\[] | null; segments activityentry\[] | null; splits activityentry\[] | null; samples activitysamples\[] | null; routepoints activitysamples\[] | null; } backgrdound 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 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 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 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 import spikesdk override func application( application uiapplication, didfinishlaunchingwithoptions launchoptions \[uiapplication launchoptionskey any]? = nil) > bool { spike configure() } or appdelegate mm \#import \<spikesdk/spikesdk swift h> \ (bool)application (uiapplication )application didfinishlaunchingwithoptions (nsdictionary )launchoptions { \[spike configure]; } 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 ) 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 setup add the following permission to your androidmanifest xml \<uses permission android\ name="android permission health read health data in background" /> react native specific add includebackgrounddelivery true when asking for permissions spikeconnection requesthealthpermissions({ statistictypes statistictypes, includebackgrounddelivery true, }) you can also ask for background delivery permission at the same time as other permissions now you can enable background delivery try { await spikeconnection enablebackgrounddelivery({ statistictypes \[statisticstype steps, statisticstype distancetotal], sleepconfigs \[new sleepconfig({ includemetrictypes \[], })], }) toast show("background delivery enabled") } catch (error) { console log(`${error}`); toast show(`${error}`); } catch (error) { console log(`${error}`); } 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