diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.h b/RCTAppleHealthKit/RCTAppleHealthKit+Methods_Characteristic.h new file mode 100644 index 0000000000000000000000000000000000000000..6c0adcceee71627374b47e04caa5ed5ec94abf0b --- /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 0000000000000000000000000000000000000000..a874c05d3fc0f28249e7fb6201b0daeba1665a51 --- /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