react-native-spike-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +184 -0
- package/android/build.gradle +82 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/spikesdk/SpikeSdkModule.kt +18 -0
- package/android/src/main/java/com/spikesdk/SpikeSdkPackage.kt +17 -0
- package/ios/SpikeSdk-Bridging-Header.h +2 -0
- package/ios/SpikeSdk.m +36 -0
- package/ios/SpikeSdk.swift +135 -0
- package/ios/SpikeSdk.xcodeproj/project.pbxproj +281 -0
- package/ios/SpikeSdk.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/SpikeSdk.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/SpikeSdk.xcodeproj/project.xcworkspace/xcuserdata/ekroman.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/SpikeSdk.xcodeproj/xcuserdata/ekroman.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/lib/commonjs/Spike.js +68 -0
- package/lib/commonjs/Spike.js.map +1 -0
- package/lib/commonjs/SpikeDataType.js +2 -0
- package/lib/commonjs/SpikeDataType.js.map +1 -0
- package/lib/commonjs/SpikeInterface.js +6 -0
- package/lib/commonjs/SpikeInterface.js.map +1 -0
- package/lib/commonjs/SpikeResultData.js +2 -0
- package/lib/commonjs/SpikeResultData.js.map +1 -0
- package/lib/commonjs/SpikeSdk.js +18 -0
- package/lib/commonjs/SpikeSdk.js.map +1 -0
- package/lib/commonjs/index.js +19 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/useSpikeEvents.js +36 -0
- package/lib/commonjs/useSpikeEvents.js.map +1 -0
- package/lib/module/Spike.js +61 -0
- package/lib/module/Spike.js.map +1 -0
- package/lib/module/SpikeDataType.js +2 -0
- package/lib/module/SpikeDataType.js.map +1 -0
- package/lib/module/SpikeInterface.js +2 -0
- package/lib/module/SpikeInterface.js.map +1 -0
- package/lib/module/SpikeResultData.js +2 -0
- package/lib/module/SpikeResultData.js.map +1 -0
- package/lib/module/SpikeSdk.js +11 -0
- package/lib/module/SpikeSdk.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/useSpikeEvents.js +29 -0
- package/lib/module/useSpikeEvents.js.map +1 -0
- package/lib/typescript/Spike.d.ts +14 -0
- package/lib/typescript/Spike.d.ts.map +1 -0
- package/lib/typescript/SpikeDataType.d.ts +2 -0
- package/lib/typescript/SpikeDataType.d.ts.map +1 -0
- package/lib/typescript/SpikeInterface.d.ts +13 -0
- package/lib/typescript/SpikeInterface.d.ts.map +1 -0
- package/lib/typescript/SpikeResultData.d.ts +26 -0
- package/lib/typescript/SpikeResultData.d.ts.map +1 -0
- package/lib/typescript/SpikeSdk.d.ts +2 -0
- package/lib/typescript/SpikeSdk.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +9 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/useSpikeEvents.d.ts +10 -0
- package/lib/typescript/useSpikeEvents.d.ts.map +1 -0
- package/package.json +131 -0
- package/react-native-spike-sdk.podspec +44 -0
- package/src/Spike.ts +76 -0
- package/src/SpikeDataType.ts +8 -0
- package/src/SpikeInterface.ts +26 -0
- package/src/SpikeResultData.ts +25 -0
- package/src/SpikeSdk.ts +18 -0
- package/src/index.ts +18 -0
- package/src/useSpikeEvents.ts +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2020 SpikeAPI <vytenis@spikeapi.com >
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# Spike ReactNative SDK
|
|
2
|
+
|
|
3
|
+
Spike API for health and productivity data from wearables and IoT devices
|
|
4
|
+
|
|
5
|
+
# Table of contents
|
|
6
|
+
|
|
7
|
+
- [Requirements](#requirements)
|
|
8
|
+
- [Installation](#installation)
|
|
9
|
+
- [Configure and Start](#configure)
|
|
10
|
+
- [Setup SpikeSDKDelegate](#delegate)
|
|
11
|
+
- [Setup SpikeSDK](#setup_sdk)
|
|
12
|
+
- [Get data](#get_data)
|
|
13
|
+
- [Enable debug mode](#debug)
|
|
14
|
+
- [Background data updates](#background_updates)
|
|
15
|
+
|
|
16
|
+
## Requirements <a name="requirements"></a>
|
|
17
|
+
|
|
18
|
+
- iOS 13.0+
|
|
19
|
+
|
|
20
|
+
#### Add Capabilities
|
|
21
|
+
|
|
22
|
+
To add HealthKit support to your application's `Capabilities`
|
|
23
|
+
|
|
24
|
+
- Open the `ios/` folder of your project in Xcode
|
|
25
|
+
- Select the project name in the left sidebar
|
|
26
|
+
- Open `Signing & Capabilities` section.
|
|
27
|
+
- In the main view select '+ Capability' and double click `HealthKit`
|
|
28
|
+
- Allow `Clinical Health Records` and `Background Delivery` if needed.
|
|
29
|
+
|
|
30
|
+
#### Update Info.plist
|
|
31
|
+
|
|
32
|
+
Add Health Kit permissions descriptions to your `ios/<Project Name>/Info.plist` file.
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
<key>NSHealthShareUsageDescription</key>
|
|
36
|
+
<string>We will use your health information to better track Prancercise workouts.</string>
|
|
37
|
+
|
|
38
|
+
<key>NSHealthUpdateUsageDescription</key>
|
|
39
|
+
<string>We will update your health information to better track Prancercise workouts.</string>
|
|
40
|
+
|
|
41
|
+
<key>NSHealthClinicalHealthRecordsShareUsageDescription</key>
|
|
42
|
+
<string>We will use your health information to better track Prancercise workouts.</string>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Installation <a name="installation"></a>
|
|
46
|
+
|
|
47
|
+
Install the react-native-spike-sdk package from [npm](https://www.npmjs.com/package/react-native-spike-sdk)
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
yarn add react-native-spike-sdk
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Use `pod install` and `pod update` commands from `ios/` folder of your app to install/update pods afterward.
|
|
54
|
+
|
|
55
|
+
## Configure and Start <a name="configure"></a>
|
|
56
|
+
|
|
57
|
+
Import SpikeSDK
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
import Spike from 'react-native-spike-sdk';
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Add Spike initialization code to `App.tsx` file outside the App component.
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
Spike.initialize();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Setup SpikeSDK Events <a name="delegate"></a>
|
|
70
|
+
|
|
71
|
+
Use `useSpikeEvents` hook to handle results from SpikeSDK.
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
import Spike, { useSpikeEvents } from 'react-native-spike-sdk';
|
|
75
|
+
|
|
76
|
+
...
|
|
77
|
+
|
|
78
|
+
useSpikeEvents({
|
|
79
|
+
onInitialize: (uuid) => {
|
|
80
|
+
console.log(`Event: onInitialize: ${uuid}`);
|
|
81
|
+
},
|
|
82
|
+
onInitializationFailure: () => {
|
|
83
|
+
console.log('Event: onInitializationFailure');
|
|
84
|
+
},
|
|
85
|
+
onDataResult: (result) => {
|
|
86
|
+
console.log(`Event: onDataResult: ${JSON.stringify(result)}`);
|
|
87
|
+
},
|
|
88
|
+
onDataFailure: () => {
|
|
89
|
+
console.log('Event: onDataFailure');
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Setup SpikeSDK <a name="setup_sdk"></a>
|
|
95
|
+
|
|
96
|
+
Provide `SpikeSDK` with client id, authorization token, user id and optionally postback url.
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
Spike.setup({CLIENT_ID}, {AUTH_TOKEN}, {USER_ID}, {URL/undefined});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Check for current session `Promise<string | undefined>`:
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
await Spike.getCurrentUUID()
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Remove session data:
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
Spike.clearData()
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Get data <a name="get_data"></a>
|
|
115
|
+
|
|
116
|
+
Get data for specified Spike Data types.
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
import Spike, { SpikeDataTypesAll } from 'react-native-spike-sdk';
|
|
120
|
+
|
|
121
|
+
...
|
|
122
|
+
|
|
123
|
+
Spike.getData(SpikeDataTypesAll);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
or
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
Spike.getData(['DataTypeHeartRate', 'DataTypeBasalEnergy'])
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
All available Data types `SpikeDataType` or use all of the instantly `SpikeDataTypesAll`:
|
|
133
|
+
`DataTypeStep`
|
|
134
|
+
`DataTypeHeartRate`
|
|
135
|
+
`DataTypeRestingHeartRate`
|
|
136
|
+
`DataTypeActiveEnergy`
|
|
137
|
+
`DataTypeBasalEnergy`
|
|
138
|
+
`DataTypeAppleMoveTime`
|
|
139
|
+
`DataTypeAppleExerciseTime`
|
|
140
|
+
|
|
141
|
+
### Enable debug mode <a name="debug"></a>
|
|
142
|
+
|
|
143
|
+
With enabled debug mode SpikeSDK will print performed actions.
|
|
144
|
+
You can see logs directly running application from Xcode. Use logs filter `[SpikeSDK]`.
|
|
145
|
+
It is better to call this before calling `Spike.initialize();`.
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
Spike.enableDebug();
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Background data updates <a name="background_updates"></a>
|
|
152
|
+
|
|
153
|
+
Allow update data for specified Spike Data types and send it to Spike.
|
|
154
|
+
|
|
155
|
+
#### Add Capabilities
|
|
156
|
+
|
|
157
|
+
Go to your target's `Signing & Capabilities` section and add Background Modes. Allow `Background fetch`. And check `Info.plist` for `UIBackgroundModes`.
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
...
|
|
161
|
+
<key>UIBackgroundModes</key>
|
|
162
|
+
<array>
|
|
163
|
+
<string>fetch</string>
|
|
164
|
+
</array>
|
|
165
|
+
...
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### Enable/Disable data background delivery
|
|
169
|
+
|
|
170
|
+
Enable Health data background delivery for specified Spike Data types.
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
Spike.enableBackgroundDelivery(SpikeDataTypesAll);
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
Spike.disableAllBackgroundDelivery();
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Check is background delivery is enabled `Promise<boolean>`.
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
await Spike.isBackgroundUpdateEnabled();
|
|
184
|
+
```
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
|
3
|
+
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["SpikeSdk_kotlinVersion"]
|
|
4
|
+
|
|
5
|
+
repositories {
|
|
6
|
+
google()
|
|
7
|
+
mavenCentral()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
dependencies {
|
|
11
|
+
classpath "com.android.tools.build:gradle:7.2.1"
|
|
12
|
+
// noinspection DifferentKotlinGradleVersion
|
|
13
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
def isNewArchitectureEnabled() {
|
|
18
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
apply plugin: "com.android.library"
|
|
22
|
+
apply plugin: "kotlin-android"
|
|
23
|
+
|
|
24
|
+
if (isNewArchitectureEnabled()) {
|
|
25
|
+
apply plugin: "com.facebook.react"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
def getExtOrDefault(name) {
|
|
29
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["SpikeSdk_" + name]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
def getExtOrIntegerDefault(name) {
|
|
33
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["SpikeSdk_" + name]).toInteger()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
android {
|
|
37
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
38
|
+
|
|
39
|
+
defaultConfig {
|
|
40
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
41
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
42
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
43
|
+
}
|
|
44
|
+
buildTypes {
|
|
45
|
+
release {
|
|
46
|
+
minifyEnabled false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
lintOptions {
|
|
51
|
+
disable "GradleCompatible"
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
compileOptions {
|
|
55
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
56
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
repositories {
|
|
62
|
+
mavenCentral()
|
|
63
|
+
google()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
67
|
+
|
|
68
|
+
dependencies {
|
|
69
|
+
// For < 0.71, this will be from the local maven repo
|
|
70
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
71
|
+
//noinspection GradleDynamicVersion
|
|
72
|
+
implementation "com.facebook.react:react-native"
|
|
73
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (isNewArchitectureEnabled()) {
|
|
77
|
+
react {
|
|
78
|
+
jsRootDir = file("../src/")
|
|
79
|
+
libraryName = "SpikeSdk"
|
|
80
|
+
codegenJavaPackageName = "com.spikesdk"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
package com.spikesdk
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
5
|
+
import com.facebook.react.bridge.ReactMethod
|
|
6
|
+
import com.facebook.react.bridge.Promise
|
|
7
|
+
|
|
8
|
+
class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
9
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
10
|
+
|
|
11
|
+
override fun getName(): String {
|
|
12
|
+
return NAME
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
companion object {
|
|
16
|
+
const val NAME = "SpikeSdk"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.spikesdk
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SpikeSdkPackage : ReactPackage {
|
|
10
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
11
|
+
return listOf(SpikeSdkModule(reactContext))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
15
|
+
return emptyList()
|
|
16
|
+
}
|
|
17
|
+
}
|
package/ios/SpikeSdk.m
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
#import <React/RCTEventEmitter.h>
|
|
3
|
+
|
|
4
|
+
@interface RCT_EXTERN_MODULE(SpikeSdk, RCTEventEmitter)
|
|
5
|
+
|
|
6
|
+
RCT_EXTERN_METHOD(isBackgroundUpdateEnabled: (RCTPromiseResolveBlock)resolve
|
|
7
|
+
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
8
|
+
|
|
9
|
+
RCT_EXTERN_METHOD(enableDebug)
|
|
10
|
+
|
|
11
|
+
RCT_EXTERN_METHOD(initialize)
|
|
12
|
+
|
|
13
|
+
RCT_EXTERN_METHOD(setupWithURL: (NSString)clientId
|
|
14
|
+
withAuthToken: (NSString)authToken
|
|
15
|
+
withUserId: (NSString)userId
|
|
16
|
+
withPostbackURL: (NSString)postbackURL)
|
|
17
|
+
|
|
18
|
+
RCT_EXTERN_METHOD(setup: (NSString)clientId
|
|
19
|
+
withAuthToken: (NSString)authToken
|
|
20
|
+
withUserId: (NSString)userId)
|
|
21
|
+
|
|
22
|
+
RCT_EXTERN_METHOD(getCurrentUUID: (RCTPromiseResolveBlock)resolve
|
|
23
|
+
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
24
|
+
|
|
25
|
+
RCT_EXTERN_METHOD(clearData)
|
|
26
|
+
|
|
27
|
+
RCT_EXTERN_METHOD(getData: (NSArray<NSString>)dataTypes)
|
|
28
|
+
|
|
29
|
+
RCT_EXTERN_METHOD(enableBackgroundDelivery: (NSArray<NSString>)dataTypes
|
|
30
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
31
|
+
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
32
|
+
|
|
33
|
+
RCT_EXTERN_METHOD(disableAllBackgroundDelivery: (RCTPromiseResolveBlock)resolve
|
|
34
|
+
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
35
|
+
|
|
36
|
+
@end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import SpikeSDK
|
|
3
|
+
import React
|
|
4
|
+
|
|
5
|
+
@objc(SpikeSdk)
|
|
6
|
+
class SpikeSdk: RCTEventEmitter {
|
|
7
|
+
|
|
8
|
+
override init() {
|
|
9
|
+
super.init()
|
|
10
|
+
|
|
11
|
+
Spike.shared.delegate = self
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@objc(isBackgroundUpdateEnabled:withRejecter:)
|
|
15
|
+
func isBackgroundUpdateEnabled(resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
16
|
+
resolve(Spike.shared.isBackgroundUpdateEnabled)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@objc(enableDebug)
|
|
20
|
+
func enableDebug() {
|
|
21
|
+
Spike.shared.enableDebug()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@objc(initialize)
|
|
25
|
+
func initialize() {
|
|
26
|
+
Spike.shared.initialize()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@objc(setup:withAuthToken:withUserId:)
|
|
30
|
+
func setup(clientId: String,
|
|
31
|
+
authToken: String,
|
|
32
|
+
userId: String) {
|
|
33
|
+
Spike.shared.setup(clientId: clientId, authToken: authToken, userId: userId)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@objc(setupWithURL:withAuthToken:withUserId:withPostbackURL:)
|
|
37
|
+
func setupWithURL(clientId: String,
|
|
38
|
+
authToken: String,
|
|
39
|
+
userId: String,
|
|
40
|
+
postbackURL: String?) {
|
|
41
|
+
Spike.shared.setup(clientId: clientId, authToken: authToken, userId: userId, postbackURL: postbackURL)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@objc(getCurrentUUID:withRejecter:)
|
|
45
|
+
func getCurrentUUID(resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
46
|
+
resolve(Spike.shared.getCurrentUUID() ?? "")
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@objc(clearData)
|
|
50
|
+
func clearData() {
|
|
51
|
+
Spike.shared.clearData()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@objc(getData:)
|
|
55
|
+
func getData(dataTypes: [String]) {
|
|
56
|
+
let types = extractDataTypes(dataTypes)
|
|
57
|
+
Spike.shared.getData(for: types)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@objc(enableBackgroundDelivery:withResolver:withRejecter:)
|
|
61
|
+
func enableBackgroundDelivery(dataTypes: [String],
|
|
62
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
63
|
+
reject: RCTPromiseRejectBlock) {
|
|
64
|
+
let types = extractDataTypes(dataTypes)
|
|
65
|
+
Spike.shared.enableBackgroundDelivery(for: types) {
|
|
66
|
+
resolve(Void.self)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@objc(disableAllBackgroundDelivery:withRejecter:)
|
|
71
|
+
func disableAllBackgroundDelivery(resolve: @escaping RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
72
|
+
Spike.shared.disableAllBackgroundDelivery() {
|
|
73
|
+
resolve(Void.self)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
override func supportedEvents() -> [String]! {
|
|
78
|
+
return [
|
|
79
|
+
"onInitialize",
|
|
80
|
+
"onInitializationFailure",
|
|
81
|
+
"onDataResult",
|
|
82
|
+
"onDataFailure",
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
override static func requiresMainQueueSetup() -> Bool {
|
|
87
|
+
return true
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private func extractDataTypes(_ types: [String]) -> [SpikeDataTypes] {
|
|
91
|
+
return types.compactMap { type in
|
|
92
|
+
switch (type) {
|
|
93
|
+
case "DataTypeStep":
|
|
94
|
+
return SpikeDataTypes.step
|
|
95
|
+
case "DataTypeHeartRate":
|
|
96
|
+
return SpikeDataTypes.heartRate
|
|
97
|
+
case "DataTypeRestingHeartRate":
|
|
98
|
+
return SpikeDataTypes.restingHeartRate
|
|
99
|
+
case "DataTypeActiveEnergy":
|
|
100
|
+
return SpikeDataTypes.activeEnergy
|
|
101
|
+
case "DataTypeBasalEnergy":
|
|
102
|
+
return SpikeDataTypes.basalEnergy
|
|
103
|
+
case "DataTypeAppleMoveTime":
|
|
104
|
+
return SpikeDataTypes.appleMoveTime
|
|
105
|
+
case "DataTypeAppleExerciseTime":
|
|
106
|
+
return SpikeDataTypes.appleExerciseTime
|
|
107
|
+
default:
|
|
108
|
+
return nil
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
extension SpikeSdk: SpikeDelegate {
|
|
115
|
+
|
|
116
|
+
func spikeInitialized(with uuid: String) {
|
|
117
|
+
sendEvent(withName: "onInitialize", body: ["uuid": uuid])
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
func spikeInitializationFailure() {
|
|
121
|
+
sendEvent(withName: "onInitializationFailure", body: [:])
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
func spikeDataResult(_ result: [SpikeResultData]) {
|
|
125
|
+
if let dataString = try? String(data: JSONEncoder().encode(result), encoding: .utf8){
|
|
126
|
+
sendEvent(withName: "onDataResult", body: ["resultJson": dataString])
|
|
127
|
+
} else {
|
|
128
|
+
sendEvent(withName: "onDataResult", body: ["resultJson": "[]"])
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
func spikeDataFailure() {
|
|
133
|
+
sendEvent(withName: "onDataFailure", body: [:])
|
|
134
|
+
}
|
|
135
|
+
}
|