lucaspbordignon / rn-apple-healthkit

A React Native package for interacting with Apple HealthKit
https://www.npmjs.com/package/react-native-health
MIT License
519 stars 296 forks source link

Save Food #33

Open s-turcheniuk opened 6 years ago

s-turcheniuk commented 6 years ago

I have a few questions about 'save food' feature:

  1. Why it is not presented in read me while it is available in the source code?

  2. I found that saveFood is not very stable. Sometimes it saves food, but most of the time it doesn't. Also, the callback function is not getting called when it doesn't save, which makes it is very hard to suggest what is going wrong. Any thoughts about it?

s-turcheniuk commented 6 years ago

@terrillo Is there an update?

Eyesonly88 commented 6 years ago

Hi @zumaawad and @terrillo, the saveFood method doesn't save all the time and I'm not sure why. Have you guys got this working consistently? is there some configuration that I'm missing? Can you please help 🙏

csumrell commented 6 years ago

@zumaawad @Eyesonly88 would you guys mind sharing your code? Every time I try to use saveFood (or saveWater) my app crashes with EXC_BAD_ACCESS

    let foodOptions = {
        carbohydrates: 25,
        energy: 1000,
        fatTotal: 100,
        protein: 50,
        fiber: 20,
        date:  new Date().toISOString(),
        mealType: "Breakfast",
        foodName: "TestName"
    };

AppleHealthKit.initHealthKit(
        (healthKitOptions: Object),
        (err: string, results: Object) => {
            if (err) {
                console.log("error initializing Healthkit: ", err);
                return;
            }

            AppleHealthKit.saveFood(
                (foodOptions: Object),
                (err: Object, results: Object) => {
                    if (err) {
                        console.log("error saving water to Healthkit: ", err);
                        return;
                    }
                }
            );
        }
    );
svbutko commented 5 years ago

@s-turcheniuk @Eyesonly88 @csumrell I found why it happens and fixed it. The issue was that the file that has saveFood method is not added into the project. This PR fixes it