Commit b3c187be authored by Greg Wilson's avatar Greg Wilson

implemented fitness_initializeStepEventObserver and exported RCT initStepCountObserver method

parent 4c74ce16
......@@ -18,6 +18,8 @@
- (void)fitness_saveSteps:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_initializeStepEventObserver:(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;
......
......@@ -10,8 +10,12 @@
#import "RCTAppleHealthKit+Queries.h"
#import "RCTAppleHealthKit+Utils.h"
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
@implementation RCTAppleHealthKit (Methods_Fitness)
//- (void)fitness_getStepCountForToday:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
//{
// HKQuantityType *stepCountType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
......@@ -156,6 +160,38 @@
- (void)fitness_initializeStepEventObserver:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKSampleType *sampleType =
[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
HKObserverQuery *query =
[[HKObserverQuery alloc]
initWithSampleType:sampleType
predicate:nil
updateHandler:^(HKObserverQuery *query,
HKObserverQueryCompletionHandler completionHandler,
NSError *error) {
if (error) {
// Perform Proper Error Handling Here...
NSLog(@"*** An error occured while setting up the stepCount observer. %@ ***", error.localizedDescription);
callback(@[RCTMakeError(@"An error occured while setting up the stepCount observer", error, nil)]);
return;
}
[self.bridge.eventDispatcher sendAppEventWithName:@"change:steps"
body:@{@"name": @"change:steps"}];
// If you have subscribed for background updates you must call the completion handler here.
// completionHandler();
}];
[self.healthStore executeQuery:query];
}
- (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
......
......@@ -17,8 +17,14 @@
#import "RCTAppleHealthKit+Methods_Vitals.h"
#import "RCTAppleHealthKit+Methods_Results.h"
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
@implementation RCTAppleHealthKit
@synthesize bridge = _bridge;
RCT_EXPORT_MODULE();
......@@ -32,6 +38,11 @@ RCT_EXPORT_METHOD(initHealthKit:(NSDictionary *)input callback:(RCTResponseSende
[self initializeHealthKit:input callback:callback];
}
RCT_EXPORT_METHOD(initStepCountObserver:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self fitness_initializeStepEventObserver:input callback:callback];
}
RCT_EXPORT_METHOD(getBiologicalSex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self characteristic_getBiologicalSex:input callback:callback];
......@@ -181,7 +192,7 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock
- (void)initializeHealthKit:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
self.healthStore = [[HKHealthStore alloc] init];
if ([HKHealthStore isHealthDataAvailable]) {
NSSet *writeDataTypes;
NSSet *readDataTypes;
......@@ -193,7 +204,7 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock
NSArray* writePermsArray = [permissions objectForKey:@"write"];
NSSet* readPerms = [self getReadPermsFromOptions:readPermsArray];
NSSet* writePerms = [self getWritePermsFromOptions:writePermsArray];
if(readPerms != nil) {
readDataTypes = readPerms;
}
......
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