Commit 2178a8ed authored by Evgenii Evstropov's avatar Evgenii Evstropov

add function to check share(write) permissions authorisation

parent 9c5f2734
......@@ -10,6 +10,8 @@
@interface RCTAppleHealthKit (TypesAndPermissions)
- (NSDictionary *)readPermsDict;
- (NSDictionary *)writePermsDict;
- (NSSet *)getReadPermsFromOptions:(NSArray *)options;
- (NSSet *)getWritePermsFromOptions:(NSArray *)options;
......
......@@ -83,7 +83,6 @@
return writePerms;
}
// Returns HealthKit read permissions from options array
- (NSSet *)getReadPermsFromOptions:(NSArray *)options {
NSDictionary *readPermDict = [self readPermsDict];
......
......@@ -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
......@@ -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 = @{
......
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