Commit cc75e483 authored by Andreas Amsenius's avatar Andreas Amsenius

Add authorizationStatusForType

Add bridge method for HKHealthStore.authorizationStatusForType to be
able to determine if user actually granted certain write permission.

See: https://developer.apple.com/documentation/healthkit/hkhealthstore/1614154-authorizationstatusfortype?language=objc
parent 950fe096
...@@ -13,5 +13,7 @@ ...@@ -13,5 +13,7 @@
- (NSSet *)getReadPermsFromOptions:(NSArray *)options; - (NSSet *)getReadPermsFromOptions:(NSArray *)options;
- (NSSet *)getWritePermsFromOptions:(NSArray *)options; - (NSSet *)getWritePermsFromOptions:(NSArray *)options;
- (HKObjectType *)getWritePermFromString:(NSString *)string;
- (NSString *)getAuthorizationStatusString:(HKAuthorizationStatus)status;
@end @end
...@@ -150,4 +150,18 @@ ...@@ -150,4 +150,18 @@
return writePermSet; return writePermSet;
} }
- (HKObjectType *)getWritePermFromString:(NSString *)writePerm {
return [[self writePermsDict] objectForKey:writePerm];
}
- (NSString *)getAuthorizationStatusString:(HKAuthorizationStatus)status {
switch (status) {
case HKAuthorizationStatusNotDetermined:
return @"NotDetermined";
case HKAuthorizationStatusSharingDenied:
return @"SharingDenied";
case HKAuthorizationStatusSharingAuthorized:
return @"SharingAuthorized";
}
}
@end @end
...@@ -268,6 +268,26 @@ RCT_EXPORT_METHOD(saveMindfulSession:(NSDictionary *)input callback:(RCTResponse ...@@ -268,6 +268,26 @@ RCT_EXPORT_METHOD(saveMindfulSession:(NSDictionary *)input callback:(RCTResponse
} }
} }
RCT_EXPORT_METHOD(authorizationStatusForType:(NSString *)type
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject
{
self.healthStore = [[HKHealthStore alloc] init];
if ([HKHealthStore isHealthDataAvailable]) {
HKObjectType *objectType = [self getWritePermFromString:type];
if (objectType == nil) {
reject(@"unknown write permission", nil, nil);
return;
}
NSString *status = [self getAuthorizationStatusString:[self.healthStore authorizationStatusForType:objectType]];
resolve(status);
} else {
reject(@"HealthKit data is not available", nil, nil);
}
})
- (void)getModuleInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback - (void)getModuleInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{ {
NSDictionary *info = @{ 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