Open mifi opened 5 years ago
Have you tried calling authorizationStatusForType
before trying to saveMindfulSession
?
Unfortunately that method is not available in the api. See #82
Interesting, I was able to access that method in a dummy app I just created. It was pretty straightforward.
HealthKit.initHealthKit(options, async (err) => {
if (err) return console.log("error initializing HealthKit", err);
try {
const res = await HealthKit.authorizationStatusForType('Height')
console.log('res', res) // logs 'SharingAuthorized'
} catch (e) {
console.log('error', e)
}
}
The method does seem to be available.
// RCTAppleHealthKit.m
RCT_EXPORT_METHOD(authorizationStatusForType:(NSString *)type
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject
{
if (self.healthStore == nil) {
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);
}
})
It looks like that authorizationStatusForType
code is not published to npm
For example when trying
The error object doesn't seem to have any code or anything else than message. err.code is undefined
How can I detect auth error?
/Not authorized/.test(err.message)
seems hacky