forked from yldio/react-native-wearables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.ios.js
47 lines (41 loc) · 1.06 KB
/
data.ios.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import AppleHealthKit from "rn-apple-healthkit";
import { DATA_TYPES, ERRORS } from "./constants";
const typeMappings = {
[DATA_TYPES.heartRateBpm]: AppleHealthKit.Constants.Permissions.HeartRate
};
const funcMappings = {
[DATA_TYPES.heartRateBpm]: AppleHealthKit.getHeartRateSamples
};
const Data = {
Types: DATA_TYPES,
authorize(dataTypes) {
return new Promise((resolve, reject) => {
AppleHealthKit.initHealthKit(
{
permissions: {
read: dataTypes.map(dt => typeMappings[dt])
}
},
err => {
if (err) reject(new Error(ERRORS.failedInit));
else resolve();
}
);
});
},
read(dataType, options) {
return new Promise((resolve, reject) => {
funcMappings[dataType](
{
startDate: options.startDate.toISOString(),
endDate: options.endDate.toISOString()
},
(err, samples) => {
if (err) reject(new Error(ERRORS.failedQuery));
else resolve(samples);
}
);
});
}
};
export default Data;