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

Swift

Spike Swift 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.

Requirements

  • iOS 13.0+
  • Xcode 13.0+
  • Swift 5+

Signing & Capabilities

Go to your target's Signing & Capabilities section and add HealthKit.

Allow Clinical Health Records, Background fetch, and Background Delivery.



More details you can find here.

Info.plist

Add Health Kit permissions descriptions to your Info.plist file.

Info.plist
|


Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. To integrate SpikeSDK into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'SpikeSDK', '0.2.10'

Use pod install and pod update commands to install/update pods afterward.

Configuration

1. Import SpikeSDK to your project.

import SpikeSDK

2. Add Spike initialization code to application(_:didFinishLaunchingWithOptions:) in your AppDelegate file.

Spike.shared.initialize()

3. Provide SpikeDelegate to handle results from SpikeSDK.

Spike.shared.delegate = self

4. Setup with client id, authorization token, user id, and optionally postback URL.

Spike.shared.setup(clientId: {CLIENT_ID}, authToken: {AUTH_TOKEN}, userId: {USER_ID}, postbackURL: {URL/nil})

  • If you leave postbackURL empty then SDK sends standardized data back to your app in the same request.
  • If you provide postbackURL then SDK sends standardized data back to your servers.
  • You need postbackURL if you will use Spike.shared.​enableBackgroundDelivery.

Getting Data

Get data for specified Spike Data types. All available Data types: step, heartRate, restingHeartRate, activeEnergy, basalEnergy, appleMoveTime, appleExerciseTime.

Spike.shared.getData(for: SpikeDataTypes.allCases)

Spike.shared.getData(for: [.step, .heartRate, .appleExerciseTime])

Data will be sent to your webhook if postbackURL is configured.

Background data updates

Enabling data background updates

Spike.shared.enableBackgroundDelivery(for: SpikeDataTypes.allCases)

Disabling data background updates

Spike.shared.disableAllBackgroundDelivery()

Checking background updates

Spike.shared.isBackgroundUpdateEnabled

SDK callbacks

Successful session initialization

spikeInitialized(with uuid: String)

Failed session initialization

spikeInitializationFailure()

Successful data retrieval from HealthKit

spikeDataResult(_ result: [SpikeResultData])

Failed data retrieval from HealthKit

spikeDataFailure()

Other methods

Checking Authentication

Spike.shared.getCurrentUUID()

Removing session data

Spike.shared.clearData()

Did this page help you?
Yes
No
UP NEXT
Flutter
Docs powered by archbee 
TABLE OF CONTENTS
Requirements
Signing & Capabilities
Info.plist
Installation
CocoaPods
Configuration
Getting Data
Background data updates
Enabling data background updates
Disabling data background updates
Checking background updates
SDK callbacks
Successful session initialization
Failed session initialization
Successful data retrieval from HealthKit
Failed data retrieval from HealthKit
Other methods
Checking Authentication
Removing session data