【问题标题】:_rnAppleHealthKit.default.initHealthKit is not a function -> rn-apple-healthkit_rnAppleHealthKit.default.initHealthKit 不是函数-> rn-apple-healthkit
【发布时间】:2019-08-29 18:38:59
【问题描述】:

我正在开发一个应用程序以使用此库从 Apple Healthkit 获取健身数据:'rn-apple-healthkit'found here 但我收到错误消息:

_rnAppleHealthKit.default.initHealthKit is not a function

我按照他们的 Github 上提到的所有步骤进行操作,但没有运行 'react-native link' 命令,因为应用程序由于某些自动链接错误而停止编译。我有与 Expo 合作的经验,但这是我的第一个纯 React-Native 应用程序。以下是我的代码:

//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;

我无法在其他任何地方找到解决方案。它似乎对其他人有用。 我正在使用 mac 并已将访问 HealthKit 的“能力”授予此应用程序。 请帮我解决这个问题。 TIA。

【问题讨论】:

    标签: javascript ios react-native healthkit


    【解决方案1】:

    由于 react-native(0.60 及更高版本)中的自动链接,这似乎是一个问题。您可以使用 Cocoapods 来管理依赖项。

    查看此解决方案:https://github.com/terrillo/rn-apple-healthkit/issues/102#issuecomment-530771908

    【讨论】:

    • 感谢您的回答。我开始在 Swift 中开发应用程序,这个答案将帮助任何尝试使用 rn-apple-healthkit 在 React Native 中开发的人。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多