Commit 86372b03 authored by Greg Wilson's avatar Greg Wilson

added new methods getDistanceCycling and getFlightsClimbed and exported corresponding RCT methods

parent ed6e32f5
...@@ -18,5 +18,8 @@ ...@@ -18,5 +18,8 @@
- (void)fitness_getDailyStepSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)fitness_getDailyStepSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getDistanceCyclingOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getFlightsClimbedOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
@end @end
...@@ -107,15 +107,7 @@ ...@@ -107,15 +107,7 @@
- (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit meterUnit]]; HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit meterUnit]];
NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit];
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false];
// NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
// NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
NSDate *date = [RCTAppleHealthKit dateFromOptions:input key:@"date" withDefault:[NSDate date]]; NSDate *date = [RCTAppleHealthKit dateFromOptions:input key:@"date" withDefault:[NSDate date]];
// if(startDate == nil){
// callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
// return;
// }
HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning]; HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning];
...@@ -125,22 +117,44 @@ ...@@ -125,22 +117,44 @@
callback(@[RCTMakeError(@"ERROR getting DistanceWalkingRunning", error, nil)]); callback(@[RCTMakeError(@"ERROR getting DistanceWalkingRunning", error, nil)]);
return; return;
} }
callback(@[[NSNull null], @(distance)]); callback(@[[NSNull null], @(distance)]);
}]; }];
}
//
// [self fetchCumulativeSumStatisticsCollection:quantityType unit:unit startDate:date endDate:date ascending:ascending limit:limit completion:^(NSArray *arr, NSError *err){ - (void)fitness_getDistanceCyclingOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
// if (err != nil) { {
// NSLog(@"error with fetchCumulativeSumStatisticsCollection: %@", err); HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit meterUnit]];
// callback(@[RCTMakeError(@"error with fetchCumulativeSumStatisticsCollection", err, nil)]); NSDate *date = [RCTAppleHealthKit dateFromOptions:input key:@"date" withDefault:[NSDate date]];
// return;
// } HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceCycling];
// callback(@[[NSNull null], arr]);
// }]; [self fetchSumOfSamplesOnDayForType:quantityType unit:unit day:date completion:^(double distance, NSError *error) {
if (!distance) {
NSLog(@"ERROR getting DistanceCycling: %@", error);
callback(@[RCTMakeError(@"ERROR getting DistanceCycling", error, nil)]);
return;
}
callback(@[[NSNull null], @(distance)]);
}];
} }
- (void)fitness_getFlightsClimbedOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKUnit *unit = [HKUnit countUnit];
NSDate *date = [RCTAppleHealthKit dateFromOptions:input key:@"date" withDefault:[NSDate date]];
HKQuantityType *quantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierFlightsClimbed];
[self fetchSumOfSamplesOnDayForType:quantityType unit:unit day:date completion:^(double count, NSError *error) {
if (!count) {
NSLog(@"ERROR getting FlightsClimbed: %@", error);
callback(@[RCTMakeError(@"ERROR getting FlightsClimbed", error, nil), @(count)]);
return;
}
callback(@[[NSNull null], @(count)]);
}];
}
......
...@@ -119,6 +119,16 @@ RCT_EXPORT_METHOD(getDistanceWalkingRunning:(NSDictionary *)input callback:(RCTR ...@@ -119,6 +119,16 @@ RCT_EXPORT_METHOD(getDistanceWalkingRunning:(NSDictionary *)input callback:(RCTR
[self fitness_getDistanceWalkingRunningOnDay:input callback:callback]; [self fitness_getDistanceWalkingRunningOnDay:input callback:callback];
} }
RCT_EXPORT_METHOD(getDistanceCycling:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self fitness_getDistanceCyclingOnDay:input callback:callback];
}
RCT_EXPORT_METHOD(getFlightsClimbed:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self fitness_getFlightsClimbedOnDay:input callback:callback];
}
RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
......
...@@ -25,7 +25,11 @@ const RPERMS = AppleHealthKit.Constants.Permissions.READ; ...@@ -25,7 +25,11 @@ const RPERMS = AppleHealthKit.Constants.Permissions.READ;
const HKOPTIONS = { const HKOPTIONS = {
permissions: { permissions: {
read: [RPERMS.StepCount, RPERMS.DistanceWalkingRunning], read: [
RPERMS.StepCount,
RPERMS.DistanceWalkingRunning,
RPERMS.FlightsClimbed
],
write: [WPERMS.StepCount], write: [WPERMS.StepCount],
} }
}; };
...@@ -90,6 +94,14 @@ class Home extends Component { ...@@ -90,6 +94,14 @@ class Home extends Component {
console.log('getDistanceWalkingRunning -res-> ', res); console.log('getDistanceWalkingRunning -res-> ', res);
}); });
AppleHealthKit.getFlightsClimbed(null, (err, res) => {
if(this._handleHKError(err, 'getFlightsClimbed')){
return;
}
console.log('getFlightsClimbed -res-> ', res);
});
} }
_onPressItem(key) { _onPressItem(key) {
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; }; 140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; }; 146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
378616B61D257B040027C300 /* HealthKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 378616B51D257B040027C300 /* HealthKit.framework */; }; 378616B61D257B040027C300 /* HealthKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 378616B51D257B040027C300 /* HealthKit.framework */; };
3787CCB01D25ED040080733E /* libRCTAppleHealthKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3787CCAF1D25ED010080733E /* libRCTAppleHealthKit.a */; }; 3787CCB71D25F1D60080733E /* libRCTAppleHealthKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3787CCB61D25F1D30080733E /* libRCTAppleHealthKit.a */; };
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
...@@ -91,9 +91,9 @@ ...@@ -91,9 +91,9 @@
remoteGlobalIDString = 83CBBA2E1A601D0E00E9B192; remoteGlobalIDString = 83CBBA2E1A601D0E00E9B192;
remoteInfo = React; remoteInfo = React;
}; };
3787CCAE1D25ED010080733E /* PBXContainerItemProxy */ = { 3787CCB51D25F1D30080733E /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 3787CCAA1D25ED010080733E /* RCTAppleHealthKit.xcodeproj */; containerPortal = 3787CCB11D25F1D30080733E /* RCTAppleHealthKit.xcodeproj */;
proxyType = 2; proxyType = 2;
remoteGlobalIDString = 3774C88D1D2092F20000B3F3; remoteGlobalIDString = 3774C88D1D2092F20000B3F3;
remoteInfo = RCTAppleHealthKit; remoteInfo = RCTAppleHealthKit;
...@@ -136,7 +136,7 @@ ...@@ -136,7 +136,7 @@
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; }; 146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
378616B51D257B040027C300 /* HealthKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = HealthKit.framework; path = System/Library/Frameworks/HealthKit.framework; sourceTree = SDKROOT; }; 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>"; }; 378616B71D257B040027C300 /* StepsDemo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = StepsDemo.entitlements; path = StepsDemo/StepsDemo.entitlements; sourceTree = "<group>"; };
3787CCAA1D25ED010080733E /* RCTAppleHealthKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAppleHealthKit.xcodeproj; path = "../node_modules/react-native-apple-healthkit/RCTAppleHealthKit.xcodeproj"; sourceTree = "<group>"; }; 3787CCB11D25F1D30080733E /* RCTAppleHealthKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAppleHealthKit.xcodeproj; path = "../node_modules/react-native-apple-healthkit/RCTAppleHealthKit.xcodeproj"; 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>"; }; 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; }; 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
...@@ -154,7 +154,7 @@ ...@@ -154,7 +154,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
3787CCB01D25ED040080733E /* libRCTAppleHealthKit.a in Frameworks */, 3787CCB71D25F1D60080733E /* libRCTAppleHealthKit.a in Frameworks */,
146834051AC3E58100842450 /* libReact.a in Frameworks */, 146834051AC3E58100842450 /* libReact.a in Frameworks */,
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */, 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */,
378616B61D257B040027C300 /* HealthKit.framework in Frameworks */, 378616B61D257B040027C300 /* HealthKit.framework in Frameworks */,
...@@ -268,10 +268,10 @@ ...@@ -268,10 +268,10 @@
name = Products; name = Products;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
3787CCAB1D25ED010080733E /* Products */ = { 3787CCB21D25F1D30080733E /* Products */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
3787CCAF1D25ED010080733E /* libRCTAppleHealthKit.a */, 3787CCB61D25F1D30080733E /* libRCTAppleHealthKit.a */,
); );
name = Products; name = Products;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -287,7 +287,7 @@ ...@@ -287,7 +287,7 @@
832341AE1AAA6A7D00B99B32 /* Libraries */ = { 832341AE1AAA6A7D00B99B32 /* Libraries */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
3787CCAA1D25ED010080733E /* RCTAppleHealthKit.xcodeproj */, 3787CCB11D25F1D30080733E /* RCTAppleHealthKit.xcodeproj */,
146833FF1AC3E56700842450 /* React.xcodeproj */, 146833FF1AC3E56700842450 /* React.xcodeproj */,
00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */, 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */,
00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */, 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */,
...@@ -411,8 +411,8 @@ ...@@ -411,8 +411,8 @@
ProjectRef = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */; ProjectRef = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */;
}, },
{ {
ProductGroup = 3787CCAB1D25ED010080733E /* Products */; ProductGroup = 3787CCB21D25F1D30080733E /* Products */;
ProjectRef = 3787CCAA1D25ED010080733E /* RCTAppleHealthKit.xcodeproj */; ProjectRef = 3787CCB11D25F1D30080733E /* RCTAppleHealthKit.xcodeproj */;
}, },
{ {
ProductGroup = 00C302B61ABCB90400DB3ED1 /* Products */; ProductGroup = 00C302B61ABCB90400DB3ED1 /* Products */;
...@@ -516,11 +516,11 @@ ...@@ -516,11 +516,11 @@
remoteRef = 146834031AC3E56700842450 /* PBXContainerItemProxy */; remoteRef = 146834031AC3E56700842450 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR; sourceTree = BUILT_PRODUCTS_DIR;
}; };
3787CCAF1D25ED010080733E /* libRCTAppleHealthKit.a */ = { 3787CCB61D25F1D30080733E /* libRCTAppleHealthKit.a */ = {
isa = PBXReferenceProxy; isa = PBXReferenceProxy;
fileType = archive.ar; fileType = archive.ar;
path = libRCTAppleHealthKit.a; path = libRCTAppleHealthKit.a;
remoteRef = 3787CCAE1D25ED010080733E /* PBXContainerItemProxy */; remoteRef = 3787CCB51D25F1D30080733E /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR; sourceTree = BUILT_PRODUCTS_DIR;
}; };
78C398B91ACF4ADC00677621 /* libRCTLinking.a */ = { 78C398B91ACF4ADC00677621 /* libRCTLinking.a */ = {
......
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