diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.h b/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.h index 73438fe45b41c11bc4fdd3e28277b9f7d3b0d96c..f8e304753ec0e465812a2e54407deac2d9e032c7 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.h @@ -10,6 +10,8 @@ @interface RCTAppleHealthKit (TypesAndPermissions) +- (NSDictionary *)readPermsDict; +- (NSDictionary *)writePermsDict; - (NSSet *)getReadPermsFromOptions:(NSArray *)options; - (NSSet *)getWritePermsFromOptions:(NSArray *)options; diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m b/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m index 702208127a293c0c46264c85dafc582d7c0fb71b..3d43badb2335273babba1f9fc93fd10e389ff452 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m @@ -83,7 +83,6 @@ return writePerms; } - // Returns HealthKit read permissions from options array - (NSSet *)getReadPermsFromOptions:(NSArray *)options { NSDictionary *readPermDict = [self readPermsDict]; diff --git a/RCTAppleHealthKit/RCTAppleHealthKit.h b/RCTAppleHealthKit/RCTAppleHealthKit.h index 900c6e39ccd9c0d1e04119cd4948d57d39c634c8..eadffd31556ca50c23c9e980db2e4ce033a7ddec 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit.h +++ b/RCTAppleHealthKit/RCTAppleHealthKit.h @@ -19,6 +19,7 @@ - (void)isHealthKitAvailable:(RCTResponseSenderBlock)callback; - (void)initializeHealthKit:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)checkPermission:(NSString *)input callback:(RCTResponseSenderBlock)callback; - (void)getModuleInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; @end diff --git a/RCTAppleHealthKit/RCTAppleHealthKit.m b/RCTAppleHealthKit/RCTAppleHealthKit.m index bbc9c171fecf79d630933c2c64345d1bd81e5d43..d26a7080835a02883d89a88eb8c05a0446d1bc59 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit.m @@ -36,6 +36,11 @@ RCT_EXPORT_METHOD(initHealthKit:(NSDictionary *)input callback:(RCTResponseSende [self initializeHealthKit:input callback:callback]; } +RCT_EXPORT_METHOD(checkSharePermission:(NSString *)input callback:(RCTResponseSenderBlock)callback) +{ + [self checkPermission:input callback:callback]; +} + RCT_EXPORT_METHOD(initStepCountObserver:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self fitness_initializeStepEventObserver:input callback:callback]; @@ -248,6 +253,23 @@ RCT_EXPORT_METHOD(saveMindfulSession:(NSDictionary *)input callback:(RCTResponse } } +- (void)checkPermission:(NSString *)input callback:(RCTResponseSenderBlock)callback +{ + self.healthStore = [[HKHealthStore alloc] init]; + if ([HKHealthStore isHealthDataAvailable]) { + + HKObjectType *val = [[self writePermsDict] objectForKey:input]; + + if ([self.healthStore authorizationStatusForType:val] == HKAuthorizationStatusSharingAuthorized) { + callback(@[[NSNull null], @true]); + } else { + callback(@[[NSNull null], @false]); + } + } else { + callback(@[RCTMakeError(@"HealthKit data is not available", nil, nil)]); + } +} + - (void)getModuleInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSDictionary *info = @{