Commit d443a49c authored by Greg Wilson's avatar Greg Wilson

Merge branch 'feature/js-events'

parents 4c74ce16 f15ce594
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
- (void)fitness_saveSteps:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (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_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getDistanceCyclingOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)fitness_getDistanceCyclingOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)fitness_getFlightsClimbedOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)fitness_getFlightsClimbedOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
......
...@@ -10,8 +10,12 @@ ...@@ -10,8 +10,12 @@
#import "RCTAppleHealthKit+Queries.h" #import "RCTAppleHealthKit+Queries.h"
#import "RCTAppleHealthKit+Utils.h" #import "RCTAppleHealthKit+Utils.h"
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
@implementation RCTAppleHealthKit (Methods_Fitness) @implementation RCTAppleHealthKit (Methods_Fitness)
//- (void)fitness_getStepCountForToday:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback //- (void)fitness_getStepCountForToday:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
//{ //{
// HKQuantityType *stepCountType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; // HKQuantityType *stepCountType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
...@@ -156,6 +160,38 @@ ...@@ -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 - (void)fitness_getDistanceWalkingRunningOnDay:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
......
...@@ -17,8 +17,14 @@ ...@@ -17,8 +17,14 @@
#import "RCTAppleHealthKit+Methods_Vitals.h" #import "RCTAppleHealthKit+Methods_Vitals.h"
#import "RCTAppleHealthKit+Methods_Results.h" #import "RCTAppleHealthKit+Methods_Results.h"
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
@implementation RCTAppleHealthKit @implementation RCTAppleHealthKit
@synthesize bridge = _bridge;
RCT_EXPORT_MODULE(); RCT_EXPORT_MODULE();
...@@ -32,6 +38,11 @@ RCT_EXPORT_METHOD(initHealthKit:(NSDictionary *)input callback:(RCTResponseSende ...@@ -32,6 +38,11 @@ RCT_EXPORT_METHOD(initHealthKit:(NSDictionary *)input callback:(RCTResponseSende
[self initializeHealthKit:input callback:callback]; [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) RCT_EXPORT_METHOD(getBiologicalSex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{ {
[self characteristic_getBiologicalSex:input callback:callback]; [self characteristic_getBiologicalSex:input callback:callback];
...@@ -181,7 +192,7 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock ...@@ -181,7 +192,7 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock
- (void)initializeHealthKit:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)initializeHealthKit:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
self.healthStore = [[HKHealthStore alloc] init]; self.healthStore = [[HKHealthStore alloc] init];
if ([HKHealthStore isHealthDataAvailable]) { if ([HKHealthStore isHealthDataAvailable]) {
NSSet *writeDataTypes; NSSet *writeDataTypes;
NSSet *readDataTypes; NSSet *readDataTypes;
...@@ -193,7 +204,7 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock ...@@ -193,7 +204,7 @@ RCT_EXPORT_METHOD(getInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock
NSArray* writePermsArray = [permissions objectForKey:@"write"]; NSArray* writePermsArray = [permissions objectForKey:@"write"];
NSSet* readPerms = [self getReadPermsFromOptions:readPermsArray]; NSSet* readPerms = [self getReadPermsFromOptions:readPermsArray];
NSSet* writePerms = [self getWritePermsFromOptions:writePermsArray]; NSSet* writePerms = [self getWritePermsFromOptions:writePermsArray];
if(readPerms != nil) { if(readPerms != nil) {
readDataTypes = readPerms; readDataTypes = readPerms;
} }
......
This diff is collapsed.
...@@ -9,8 +9,10 @@ import { ...@@ -9,8 +9,10 @@ import {
ScrollView, ScrollView,
Image, Image,
Text, Text,
View View,
NativeAppEventEmitter,
} from 'react-native'; } from 'react-native';
import AppleHealthKit from 'react-native-apple-healthkit'; import AppleHealthKit from 'react-native-apple-healthkit';
import styles from '../../styles/styles'; import styles from '../../styles/styles';
import History from './history'; import History from './history';
...@@ -58,6 +60,19 @@ class Home extends Component { ...@@ -58,6 +60,19 @@ class Home extends Component {
if(this._handleHKError(err, 'initHealthKit')){ if(this._handleHKError(err, 'initHealthKit')){
return; return;
} }
AppleHealthKit.initStepCountObserver({}, () => {});
var subscription = NativeAppEventEmitter.addListener(
'change:steps',
(evt) => {
console.log('change:steps EVENT!! : ', evt);
this._fetchStepsToday();
}
);
this.sub = subscription;
this._fetchStepsToday(); this._fetchStepsToday();
this._fetchStepsHistory(); this._fetchStepsHistory();
}); });
...@@ -65,6 +80,10 @@ class Home extends Component { ...@@ -65,6 +80,10 @@ class Home extends Component {
}); });
} }
componentWillUnmount() {
this.sub.remove();
}
/** /**
* get today's step count from HealthKit. on success update * get today's step count from HealthKit. on success update
* the component state * the component state
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
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 */; };
377F68B31D7A0D9C00B64DB1 /* libRCTAppleHealthKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 377F68B21D7A0D9800B64DB1 /* libRCTAppleHealthKit.a */; };
378616B61D257B040027C300 /* HealthKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 378616B51D257B040027C300 /* HealthKit.framework */; }; 378616B61D257B040027C300 /* HealthKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 378616B51D257B040027C300 /* HealthKit.framework */; };
378DCB741D3190C800E83D06 /* libRCTAppleHealthKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 378DCB731D3190C100E83D06 /* 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;
}; };
378DCB721D3190C100E83D06 /* PBXContainerItemProxy */ = { 377F68B11D7A0D9800B64DB1 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 378DCB6E1D3190C100E83D06 /* RCTAppleHealthKit.xcodeproj */; containerPortal = 377F68AD1D7A0D9800B64DB1 /* RCTAppleHealthKit.xcodeproj */;
proxyType = 2; proxyType = 2;
remoteGlobalIDString = 3774C88D1D2092F20000B3F3; remoteGlobalIDString = 3774C88D1D2092F20000B3F3;
remoteInfo = RCTAppleHealthKit; remoteInfo = RCTAppleHealthKit;
...@@ -134,9 +134,9 @@ ...@@ -134,9 +134,9 @@
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = StepsDemo/Info.plist; sourceTree = "<group>"; }; 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = StepsDemo/Info.plist; sourceTree = "<group>"; };
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = StepsDemo/main.m; sourceTree = "<group>"; }; 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = StepsDemo/main.m; sourceTree = "<group>"; };
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>"; };
377F68AD1D7A0D9800B64DB1 /* RCTAppleHealthKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAppleHealthKit.xcodeproj; path = "../node_modules/react-native-apple-healthkit/RCTAppleHealthKit.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>"; };
378DCB6E1D3190C100E83D06 /* 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,8 @@ ...@@ -154,7 +154,8 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
378DCB741D3190C800E83D06 /* libRCTAppleHealthKit.a in Frameworks */, 377F68B31D7A0D9C00B64DB1 /* libRCTAppleHealthKit.a in Frameworks */,
139FDEF61B0652A700C62182 /* libRCTWebSocket.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 */,
...@@ -165,7 +166,6 @@ ...@@ -165,7 +166,6 @@
139105C61AF99C1200B5F7CC /* libRCTSettings.a in Frameworks */, 139105C61AF99C1200B5F7CC /* libRCTSettings.a in Frameworks */,
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */, 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */,
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */, 00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */,
139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -268,10 +268,10 @@ ...@@ -268,10 +268,10 @@
name = Products; name = Products;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
378DCB6F1D3190C100E83D06 /* Products */ = { 377F68AE1D7A0D9800B64DB1 /* Products */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
378DCB731D3190C100E83D06 /* libRCTAppleHealthKit.a */, 377F68B21D7A0D9800B64DB1 /* 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 = (
378DCB6E1D3190C100E83D06 /* RCTAppleHealthKit.xcodeproj */, 377F68AD1D7A0D9800B64DB1 /* 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 = 378DCB6F1D3190C100E83D06 /* Products */; ProductGroup = 377F68AE1D7A0D9800B64DB1 /* Products */;
ProjectRef = 378DCB6E1D3190C100E83D06 /* RCTAppleHealthKit.xcodeproj */; ProjectRef = 377F68AD1D7A0D9800B64DB1 /* 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;
}; };
378DCB731D3190C100E83D06 /* libRCTAppleHealthKit.a */ = { 377F68B21D7A0D9800B64DB1 /* libRCTAppleHealthKit.a */ = {
isa = PBXReferenceProxy; isa = PBXReferenceProxy;
fileType = archive.ar; fileType = archive.ar;
path = libRCTAppleHealthKit.a; path = libRCTAppleHealthKit.a;
remoteRef = 378DCB721D3190C100E83D06 /* PBXContainerItemProxy */; remoteRef = 377F68B11D7A0D9800B64DB1 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR; sourceTree = BUILT_PRODUCTS_DIR;
}; };
78C398B91ACF4ADC00677621 /* libRCTLinking.a */ = { 78C398B91ACF4ADC00677621 /* libRCTLinking.a */ = {
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
* on the same Wi-Fi network. * on the same Wi-Fi network.
*/ */
// //
jsCodeLocation = [NSURL URLWithString:@"http://192.168.0.14:8081/index.ios.bundle?platform=ios&dev=true"]; jsCodeLocation = [NSURL URLWithString:@"http://192.168.0.13:8081/index.ios.bundle?platform=ios&dev=true"];
// jsCodeLocation = [NSURL URLWithString:@"http://10.1.14.163:8081/index.ios.bundle?platform=ios&dev=true"]; // jsCodeLocation = [NSURL URLWithString:@"http://10.1.14.163:8081/index.ios.bundle?platform=ios&dev=true"];
/** /**
* OPTION 2 * OPTION 2
......
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