GregWilson / react-native-apple-healthkit

A React Native bridge module for interacting with Apple HealthKit data
177 stars 42 forks source link

_reactNativeAppleHealthkit2.default.isAvailable is not a function #24

Open svschannak opened 7 years ago

svschannak commented 7 years ago

Hello everybody,

this is my current Code:

import React, { Component } from "react";
import { Image, View } from 'react-native';
import { Container, Icon, DeckSwiper, Card, CardItem, Left, Right, Body, Thumbnail, Text } from 'native-base';
import AppleHealthKit from 'react-native-apple-healthkit';

const HKPERMS = AppleHealthKit.Constants.Permissions;
const HKOPTIONS = {
    permissions: {
        read:  [
            HKPERMS.StepCount,
            HKPERMS.DistanceWalkingRunning,
            HKPERMS.FlightsClimbed,
            HKPERMS.Height,
            HKPERMS.DateOfBirth,
            HKPERMS.BiologicalSex,
            HKPERMS.SleepAnalysis,
        ],
        write: [
            HKPERMS.StepCount
        ],
    }
};

class Health extends Component{
    constructor(props){
        super(props);

    }

    componentDidMount(){

        AppleHealthKit.isAvailable((err, res) => {
            if(err) {
                console.log("error initializing healthkit: ", err);
                return;
            }
            // healthkit initialized...
        });
    }

    render(){

        return(
            <Text>tbd</Text>
        )
    }
}

export default Health;

The Moment the function isAvailable is called i get the following error:

Unhandled JS Exception: _reactNativeAppleHealthkit2.default.isAvailable is not a function
reactConsoleErrorHandler @ ExceptionsManager.js:71
console.error @ YellowBox.js:62
logIfNoNativeHook @ RCTLog.js:38
__callFunction @ MessageQueue.js:242
(anonymous) @ MessageQueue.js:108
guard @ MessageQueue.js:46
callFunctionReturnFlushedQueue @ MessageQueue.js:107
(anonymous) @ debuggerWorker.js:71

I am using the current version from npm.

Can you please help me in finding a way to start to fix this problem? I did every step in the README. Is it possible that i missed something while configuring the XCode-Project?

MaxMillington commented 7 years ago

@svschannak Which version of React Native are you using?

amolduse commented 7 years ago

I am too getting the same error. I have these versions - react-native-cli: 2.0.1 react-native: 0.42.2. Which version is supported?

janstuemmel commented 7 years ago

i think the latest supported version via npm is 0.39.2 submit this version in your package json and do a react-native upgrade

MaxMillington commented 7 years ago

Yes, @AmsDs we are waiting on @GregWilson to publish the latest version to npm which will support the breaking changes introduced by react native 0.40. In the mean time, you could fork the repo and then instead of installing from the npm registry just npm install from your own repo.

amolduse commented 7 years ago

Great. Thanks for quick reply

seanadkinson commented 7 years ago

@MaxMillington @AmsDs FYI I've branched and published some fixes at https://github.com/ProvataHealth/react-native-apple-healthkit

yarn add react-native-apple-healthkit-rn0.40