I have a react-native-library that has my Healthkit queries. I install this library in my main app and call all the queries. The authorization part doesn't seem to work. I guess some issue in my library's TS files.
Healthkit query:
@objc(requestAuthorization:read:resolve:withRejecter:) func requestAuthorization(toShare: NSDictionary, read: NSDictionary, resolve: @escaping RCTPromiseResolveBlock,reject: @escaping RCTPromiseRejectBlock) { let share = sampleTypesFromDictionary(typeIdentifiers: toShare); let toRead = objectTypesFromDictionary(typeIdentifiers: read); healthStore.requestAuthorization(toShare: share, read: toRead) { (success: Bool, error: Error?) in guard let err = error else { return resolve(success); } //handle error } }
TS file (index)
export declare enum HKQuantityTypeIdentifier { HeartRate = "HKQuantityTypeIdentifierHeartRate" } export type WritePermssions = { [key in HKQuantityTypeIdentifier]: boolean; }; export type ReadPermssions = { [key in HKQuantityTypeIdentifier]: boolean; }; type ReactNativeHealthkitTypeNative = { requestAuthorization( write: WritePermssions | {}, read: ReadPermssions | {} ): Promise<boolean>; };const requestAuthorization = ( read: (HKQuantityTypeIdentifier)[], write: HKQuantityTypeIdentifier[] = [] ): Promise<boolean> => { const readAuth = read.reduce((obj, cur) => { return { ...obj, [cur]: true }; }, {}); const writeAuth = write.reduce((obj, cur) => { return { ...obj, [cur]: true }; }, {}); return NativeModules.requestAuthorization(writeAuth, readAuth); }; type authorizationMethod = ( read: (HKQuantityTypeIdentifier)[], write?: HKQuantityTypeIdentifier[] ) => Promise<boolean>; type ReactNativeHealthkit = { requestAuthorization: authorizationMethod; } const MyHealthLibrary: ReactNativeHealthkit = { requestAuthorization } export default MyHealthLibrary;
In the front-end my js file:
import MyHealthLibrary, { HKQuantityTypeIdentifier } from 'my-health-library'; await MyHealthLibrary.requestAuthorization([HKQuantityTypeIdentifier.HeartRate])
Expected result:
But i get this error. Where am i going wrong here???????