website logo
⌘K
Quickstart
User
Metrics
Webhooks
Mobile SDK
V2
React Native
Flutter
Android (Kotlin)
Swift
V1
Errors
FAQ
Docs powered by
Archbee
Mobile SDK
V1

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
|
<key>NSHealthShareUsageDescription</key>
<string>We will use your health information to better track Prancercise workouts.</string>

<key>NSHealthUpdateUsageDescription</key>
<string>We will update your health information to better track Prancercise workouts.</string>

<key>NSHealthClinicalHealthRecordsShareUsageDescription</key>
<string>We will use your health information to better track Prancercise workouts.</string>


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
|
import Spike, { useSpikeEvents } from 'react-native-spike-sdk';

...

useSpikeEvents({
  onInitialize: (uuid) => {
    console.log(`Event: onInitialize: ${uuid}`);
  },
  onInitializationFailure: () => {
    console.log('Event: onInitializationFailure');
  },
  onDataResult: (result) => {
    console.log(`Event: onDataResult: ${JSON.stringify(result)}`);
  },
  onDataFailure: () => {
    console.log('Event: onDataFailure');
  },
  onWorkoutDataResult: (result: SpikeWorkoutResultData) => {
    console.log(`Event: onWorkoutDataResult: ${JSON.stringify(result)}`);
  },
  onWorkoutDataFailure: () => {
    console.log('Event: onWorkoutDataFailure');
  },
    onSleepAnalysisDataResult: (result) => {
    console.log(`Event: onSleepAnalysisDataResult: ${JSON.stringify(result)}`);
  },
  onSleepAnalysisDataFailure: () => {
    console.log('Event: onSleepAnalysisDataFailure');
  },
  onLog: (log) => {
    console.log(`Event Spike log: ${log}`);
  }
});



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.

Get historical data

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:

import Spike, { SpikeDataTypesAll } from 'react-native-spike-sdk'; ... Spike.getDataInRange(SpikeDataTypesAll, new Date('2023-01-01'), new Date('2023-01-07'));

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?
PREVIOUS
Flutter
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
Get historical data
Enable debug mode
Background data updates
Add Capabilities
Enabling data background updates
Disabling data background updates
Checking background updates
Docs powered by
Archbee