Javascript _rnapplehalthkit.default.initHealthKit不是函数->;rn苹果健康套件

Javascript _rnapplehalthkit.default.initHealthKit不是函数->;rn苹果健康套件,javascript,ios,react-native,healthkit,Javascript,Ios,React Native,Healthkit,我正在开发一个应用程序,使用此库从Apple Healthkit获取健身数据:“rn Apple Healthkit”,但我发现了错误: _rnAppleHealthKit.default.initHealthKit is not a function 我遵循了他们Github上提到的所有步骤,但没有运行 “react native link”命令,因为应用程序由于某些自动链接错误而停止编译。我有使用Expo的经验,但这是我的第一个纯React原生应用程序。以下是我的代码: //Mostly

我正在开发一个应用程序,使用此库从Apple Healthkit获取健身数据:“rn Apple Healthkit”,但我发现了错误:

_rnAppleHealthKit.default.initHealthKit is not a function
我遵循了他们Github上提到的所有步骤,但没有运行 “react native link”命令,因为应用程序由于某些自动链接错误而停止编译。我有使用Expo的经验,但这是我的第一个纯React原生应用程序。以下是我的代码:

//Mostly Auto-Generated React-native code


import AppleHealthKit from 'rn-apple-healthkit';


const PERMS = AppleHealthKit.Constants.Permissions;
const UNITS = AppleHealthKit.Constants.Units;

const options = {
 permissions: {
read: [PERMS.Weight, PERMS.SleepAnalysis]
}
};

AppleHealthKit.initHealthKit(options, (err, results) => {
  if (err) {
      console.log("error initializing Healthkit: ", err);
      return;
  }
  AppleHealthKit.getDateOfBirth(null, (err, results) => {
    if (this._handleHealthkitError(err, 'getDateOfBirth')) {
      return;
    }
      console.log(results)
    });

});
// Generated using react-native init command
const App = () => {
  return (
    <Fragment>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView>
         <ScrollView
          contentInsetAdjustmentBehavior="automatic"
           style={styles.scrollView}>
           <Header />
          {global.HermesInternal == null ? null : (
            <View style={styles.engine}>
              <Text style={styles.footer}>Engine: Hermes</Text>
            </View>
          )}
    </ScrollView>
  </SafeAreaView>
    </Fragment>
  );
};

const styles = StyleSheet.create({
//Auto-generated styling here
});
export default App;
//大部分是自动生成的本地代码
从“rn apple healthkit”导入AppleHealthKit;
const PERMS=applehealtkhit.Constants.Permissions;
常数单位=AppleHealthKit.Constants.UNITS;
常量选项={
权限:{
阅读:[PERMS.Weight,PERMS.SleepAnalysis]
}
};
AppleHealthKit.initHealthKit(选项,(错误,结果)=>{
如果(错误){
日志(“初始化Healthkit时出错:”,err);
返回;
}
AppleHealthKit.getDateOfBirth(null,(错误,结果)=>{
如果(此._handlehalthkiter错误(err,'getDateOfBirth')){
返回;
}
console.log(结果)
});
});
//使用react native init命令生成
常量应用=()=>{
返回(
{global.hermistinternal==null?null:(
引擎:爱马仕
)}
);
};
const styles=StyleSheet.create({
//此处自动生成样式
});
导出默认应用程序;
我在其他任何地方都找不到解决这个问题的办法。它似乎对其他所有人都有效。 我使用的是mac电脑,并且我已经给了这个应用程序访问HealthKit的“能力”。 请帮我解决这个问题。
TIA。

似乎是一个问题,因为react native(0.60及以上)中的自动链接。您可以使用Cocoapods来管理依赖项


签出此解决方案:

感谢您的回答。我开始在Swift中开发这个应用程序,这个答案将帮助任何试图使用rn apple healthkit在React Native中开发的人。