-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AppleHealthKit.initHealthKit is giving undefined in native 0.76.3 version #404
Comments
import { Activities, Observers, Permissions, Units } from './src/constants' const { AppleHealthKit } = require('react-native').NativeModules export const HealthKit = { Constants: { module.exports = HealthKit this is the solution. change the index.js file in node modules/react-native-health to the above code. |
Thanks its working, do you know why we have to do that and how to make that persistent even after an update |
@AxioDev Thanks for this fix. I think for now until its fully merged in I'm just going to fork it with the fix. |
Because the new react-native architecture lazy loads modules by default, require('react-native').NativeModules is an empty object at app startup time. thats why we are getting value undefined. and to make this solution permanent until PR merged you can use apply patches to the dependency.
now run npm install. to verify the changes delete node_modules and do npm install and see in react-native-health node modules index.js file latest changes are there or not. |
Thanks. I'll try this @kapilw360 |
Do you know guys why it shows me an error to the initHealthKit on the android? after applied the patch ? Thanks. |
import AppleHealthKit, { HealthValue, HealthKitPermissions } from 'react-native-health';
const permissions = {
permissions: {
read: [
AppleHealthKit.Constants.Permissions.Steps,
AppleHealthKit.Constants.Permissions.ActiveEnergyBurned,
AppleHealthKit.Constants.Permissions.ActivitySummary,
AppleHealthKit.Constants.Permissions.DistanceCycling,
AppleHealthKit.Constants.Permissions.DistanceSwimming,
AppleHealthKit.Constants.Permissions.DistanceWalkingRunning,
AppleHealthKit.Constants.Permissions.EnergyConsumed,
AppleHealthKit.Constants.Permissions.StepCount,
AppleHealthKit.Constants.Permissions.Workout,
AppleHealthKit.Constants.Permissions.Carbohydrates,
AppleHealthKit.Constants.Permissions.EnergyConsumed,
AppleHealthKit.Constants.Permissions.FatTotal,
AppleHealthKit.Constants.Permissions.Protein,
AppleHealthKit.Constants.Permissions.AppleStandTime,
AppleHealthKit.Constants.Permissions.AppleExerciseTime,
AppleHealthKit.Constants.Permissions.SleepAnalysis,
],
write: [],
},
} as HealthKitPermissions;
export const connectApp = () => {
console.log('ios connectApp called:--');
return new Promise(resolve => {
AppleHealthKit.initHealthKit(permissions, error => {
let isSuccess = true;
if (error) {
console.log('[ERROR] Cannot grant permissions!', error);
isSuccess = false;
}
resolve(isSuccess);
});
});
};
getting undefined for AppleHealthKit.initHealthKit.
i have cross check all thing installing latest version, pod install, disable new architecture but still getting undefined and isAvailable method also giving undefined.
The text was updated successfully, but these errors were encountered: