website logo
⌘K
Quickstart
User
Metrics
Webhooks
iOS SDK
Swift
Flutter
React Native
Errors
Docs powered by archbee 

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.

Installation

Install the react-native-spike-sdk package from npm

yarn add react-native-spike-sdk

Use pod install and pod update commands from ios/ folder of your app to install/update pods afterward.

Compatibility and requirements

iOS 13.0+

Add 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
  • Allow Clinical Health Records and Background Delivery if needed.

Update Info.plist

Add Health Kit permissions descriptions to your ios/<Project Name>/Info.plist file.

Info.plist
|


Configure and Start

Import SpikeSDK

import Spike from 'react-native-spike-sdk';

Add Spike initialization code to App.tsx file outside the App component.

Spike.initialize();

Setup SpikeSDK Events

Use useSpikeEvents hook to handle results from SpikeSDK.

React Native
|


Setup SpikeSDK

Provide SpikeSDK with client id, authorization token, user id and optionally postback (webhook) URL.

Spike.setup({CLIENT_ID}, {AUTH_TOKEN}, {USER_ID}, {URL/undefined});

Check for current session Promise<string | undefined>:

await Spike.getCurrentUUID()

Remove session data:

Spike.clearData()

Get Data

Get data for specified Spike Data types.

import Spike, { SpikeDataTypesAll } from 'react-native-spike-sdk'; ... Spike.getData(SpikeDataTypesAll);

or

Spike.getData(['DataTypeHeartRate', 'DataTypeBasalEnergy'])

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.

Enable debug mode

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();.

Spike.enableDebug();

Background data updates

Allow update data for specified Spike Data types and send it to Spike.

Add Capabilities

Go to your target's Signing & Capabilities section and add Background Modes. Allow Background fetch. And check Info.plist for UIBackgroundModes.

... <key>UIBackgroundModes</key> <array> <string>fetch</string> </array> ...

Enabling data background updates

Spike.enableBackgroundDelivery(SpikeDataTypesAll)

Disabling data background updates

Spike.disableAllBackgroundDelivery()

Checking background updates

await Spike.isBackgroundUpdateEnabled



Did this page help you?
Yes
No
UP NEXT
Errors
Docs powered by archbee 
TABLE OF CONTENTS
Installation
Compatibility and requirements
Add Capabilities
Update Info.plist
Configure and Start
Setup SpikeSDK Events
Setup SpikeSDK
Get Data
Enable debug mode
Background data updates
Add Capabilities
Enabling data background updates
Disabling data background updates
Checking background updates