From 9dd3d74ee28c9bfef314fd35fe44b19cebb4cc23 Mon Sep 17 00:00:00 2001 From: Greg Wilson Date: Wed, 29 Jun 2016 18:25:42 -0400 Subject: [PATCH] created new Methods_Characteristic category to handle HealthKit Characteristic methods and implemented getters for sex and dob --- ...RCTAppleHealthKit+Methods_Characteristic.h | 16 +++++ ...RCTAppleHealthKit+Methods_Characteristic.m | 62 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.h create mode 100644 RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.m diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.h new file mode 100644 index 0000000..6c0adcc --- /dev/null +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.h @@ -0,0 +1,16 @@ +// +// RCTAppleHealthKit+Methods_Characteristic.h +// RCTAppleHealthKit +// +// Created by Greg Wilson on 2016-06-29. +// Copyright © 2016 Greg Wilson. All rights reserved. +// + +#import "RCTAppleHealthKit.h" + +@interface RCTAppleHealthKit (Methods_Characteristic) + +- (void)characteristic_getBiologicalSex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)characteristic_getDateOfBirth:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +@end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.m b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.m new file mode 100644 index 0000000..a874c05 --- /dev/null +++ b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.m @@ -0,0 +1,62 @@ +// +// RCTAppleHealthKit+Methods_Characteristic.m +// RCTAppleHealthKit +// +// Created by Greg Wilson on 2016-06-29. +// Copyright © 2016 Greg Wilson. All rights reserved. +// + +#import "RCTAppleHealthKit+Methods_Characteristic.h" +#import "RCTAppleHealthKit+Utils.h" + +@implementation RCTAppleHealthKit (Methods_Characteristic) + + +- (void)characteristic_getBiologicalSex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSError *error; + HKBiologicalSexObject *bioSex = [self.healthStore biologicalSexWithError:&error]; + NSString *value; + + switch (bioSex.biologicalSex) { + case HKBiologicalSexNotSet: + value = @"unknown"; + break; + case HKBiologicalSexFemale: + value = @"female"; + break; + case HKBiologicalSexMale: + value = @"male"; + break; + case HKBiologicalSexOther: + value = @"other"; + break; + } + + if(value == nil){ + NSLog(@"error getting biological sex: %@", error); + callback(@[RCTMakeError(@"error getting biological sex", error, nil)]); + return; + } + + callback(@[[NSNull null], value]); +} + + +- (void)characteristic_getDateOfBirth:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSError *error; + NSDate *dob = [self.healthStore dateOfBirthWithError:&error]; + + if(error != nil){ + NSLog(@"error getting date of birth: %@", error); + callback(@[RCTMakeError(@"error getting date of birth", error, nil)]); + return; + } + + NSString *dobString = [RCTAppleHealthKit buildISO8601StringFromDate:dob]; + + callback(@[[NSNull null], dobString]); +} + + + +@end -- 2.26.2