Commit 9dd3d74e authored by Greg Wilson's avatar Greg Wilson

created new Methods_Characteristic category to handle HealthKit Characteristic...

created new Methods_Characteristic category to handle HealthKit Characteristic methods and implemented getters for sex and dob
parent cd29c076
//
// 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
//
// 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
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