Commit 4d738c38 authored by Greg Wilson's avatar Greg Wilson

updated code and added documentation for getSleepSamples

parent 54acd3c1
......@@ -140,7 +140,7 @@
for (HKCategorySample *sample in results) {
HKCategoryType *catType = sample.categoryType;
// HKCategoryType *catType = sample.categoryType;
NSInteger val = sample.value;
// HKQuantity *quantity = sample.quantity;
......@@ -149,9 +149,22 @@
NSString *startDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.startDate];
NSString *endDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.endDate];
NSString *valueString;
switch (val) {
case HKCategoryValueSleepAnalysisInBed:
valueString = @"INBED";
break;
case HKCategoryValueSleepAnalysisAsleep:
valueString = @"ASLEEP";
break;
default:
valueString = @"UNKNOWN";
break;
}
NSDictionary *elem = @{
@"value" : @(( (float) val )),
@"catType" : catType.identifier,
@"value" : valueString,
@"startDate" : startDateString,
@"endDate" : endDateString,
};
......
......@@ -41,6 +41,7 @@ A React Native bridge module for interacting with [Apple HealthKit] data.
* [getBloodPressureSamples](#getbloodpressuresamples)
* [getRespiratoryRateSamples](#getrespiratoryratesamples)
* [getBloodGlucoseSamples](#getbloodglucosesamples)
* [getSleepSamples](#getsleepsamples)
* [Examples](#examples)
......@@ -151,7 +152,10 @@ The available HealthKit permissions to use with `initHealthKit`
| BloodPressureSystolic | [HKQuantityTypeIdentifierBloodPressureSystolic](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbloodpressuresystolic?language=objc) | ✓ | |
| BloodPressureDiastolic | [HKQuantityTypeIdentifierBloodPressureDiastolic](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbloodpressurediastolic?language=objc) | ✓ | |
| RespiratoryRate | [HKQuantityTypeIdentifierRespiratoryRate](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierrespiratoryrate?language=objc) | ✓ | |
| BloodGlucose | [HKQuantityTypeIdentifierBloodGlucose](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbloodglucose?language=objc) | ✓ | |
| BloodGlucose | [HKQuantityTypeIdentifierBloodGlucose](https://developer.apple.com/reference/healthkit/hkquantitytypeidentifierbloodglucose?language=objc) | ✓ |
|
| SleepAnalysis | [HKCategoryTypeIdentifierSleepAnalysis](https://developer.apple.com/reference/healthkit/hkcategorytypeidentifiersleepanalysis?language=objc) | ✓ |
|
These permissions are exported as constants of the `react-native-apple-healthkit` module.
......@@ -873,6 +877,40 @@ AppleHealthKit.getBloodGlucoseSamples(options, (err: Object, samples: Array<Obje
```
___
#### **`getSleepSamples`**
query for sleep samples.
each sleep sample represents a period of time with a startDate and an endDate.
the sample's value will be either `INBED` or `ASLEEP`. these values should overlap,
meaning that two samples represent a single nights sleep activity. see
[HealthKit SleepAnalysis] reference documentation
the options object is used to setup a query to retrieve relevant samples.
the options must contain `startDate` and may also optionally include `endDate`
and `limit` options
```javascript
let options = {
startDate: (new Date(2016,10,1)).toISOString(), // required
endDate: (new Date()).toISOString(), // optional; default now
limit:10, // optional; default no limit
};
```
the callback function will be called with a `samples` array containing objects
with *value*, *startDate*, and *endDate* fields
*example usage*
```javascript
AppleHealthKit.getSleepSamples(options, (err: Object, samples: Array<Object>) => {
if(this._handleHealthKitError(err, 'getSleepSamples')){
return;
}
// use samples ...
});
```
## Examples
......@@ -892,3 +930,4 @@ AppleHealthKit.getBloodGlucoseSamples(options, (err: Object, samples: Array<Obje
[Apple HealthKit]: https://developer.apple.com/healthkit/
[react-native-apple-healthkit]: https://www.npmjs.com/package/react-native-apple-healthkit
[HealthKit SleepAnalysis]: https://developer.apple.com/reference/healthkit/hkcategoryvaluesleepanalysis?language=objc
......@@ -22,6 +22,7 @@
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
37837E961DCFE49D000201A0 /* libRCTAppleHealthKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37837E951DCFE493000201A0 /* libRCTAppleHealthKit.a */; };
378616B61D257B040027C300 /* HealthKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 378616B51D257B040027C300 /* HealthKit.framework */; };
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
/* End PBXBuildFile section */
......@@ -90,6 +91,13 @@
remoteGlobalIDString = 83CBBA2E1A601D0E00E9B192;
remoteInfo = React;
};
37837E941DCFE493000201A0 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 37837E901DCFE493000201A0 /* RCTAppleHealthKit.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 3774C88D1D2092F20000B3F3;
remoteInfo = RCTAppleHealthKit;
};
78C398B81ACF4ADC00677621 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */;
......@@ -126,6 +134,7 @@
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = StepsDemo/Info.plist; sourceTree = "<group>"; };
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = StepsDemo/main.m; sourceTree = "<group>"; };
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
37837E901DCFE493000201A0 /* RCTAppleHealthKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAppleHealthKit.xcodeproj; path = "../node_modules/react-native-apple-healthkit/RCTAppleHealthKit.xcodeproj"; sourceTree = "<group>"; };
378616B51D257B040027C300 /* HealthKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = HealthKit.framework; path = System/Library/Frameworks/HealthKit.framework; sourceTree = SDKROOT; };
378616B71D257B040027C300 /* StepsDemo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = StepsDemo.entitlements; path = StepsDemo/StepsDemo.entitlements; sourceTree = "<group>"; };
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
......@@ -145,6 +154,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
37837E961DCFE49D000201A0 /* libRCTAppleHealthKit.a in Frameworks */,
139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
146834051AC3E58100842450 /* libReact.a in Frameworks */,
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */,
......@@ -258,6 +268,14 @@
name = Products;
sourceTree = "<group>";
};
37837E911DCFE493000201A0 /* Products */ = {
isa = PBXGroup;
children = (
37837E951DCFE493000201A0 /* libRCTAppleHealthKit.a */,
);
name = Products;
sourceTree = "<group>";
};
78C398B11ACF4ADC00677621 /* Products */ = {
isa = PBXGroup;
children = (
......@@ -269,6 +287,7 @@
832341AE1AAA6A7D00B99B32 /* Libraries */ = {
isa = PBXGroup;
children = (
37837E901DCFE493000201A0 /* RCTAppleHealthKit.xcodeproj */,
146833FF1AC3E56700842450 /* React.xcodeproj */,
00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */,
00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */,
......@@ -391,6 +410,10 @@
ProductGroup = 00C302A81ABCB8CE00DB3ED1 /* Products */;
ProjectRef = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */;
},
{
ProductGroup = 37837E911DCFE493000201A0 /* Products */;
ProjectRef = 37837E901DCFE493000201A0 /* RCTAppleHealthKit.xcodeproj */;
},
{
ProductGroup = 00C302B61ABCB90400DB3ED1 /* Products */;
ProjectRef = 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */;
......@@ -493,6 +516,13 @@
remoteRef = 146834031AC3E56700842450 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
37837E951DCFE493000201A0 /* libRCTAppleHealthKit.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRCTAppleHealthKit.a;
remoteRef = 37837E941DCFE493000201A0 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
78C398B91ACF4ADC00677621 /* libRCTLinking.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
......
......@@ -9,7 +9,6 @@
"lodash": "^4.13.1",
"react": "15.1.0",
"react-mixin": "^2.0.2",
"react-native": "^0.28.0",
"react-native-apple-healthkit": "file:///Users/greg/Dev/experimental/RCTAppleHealthKit"
"react-native": "^0.28.0"
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment