【发布时间】: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