我是 React-Native 的新手,正在构建我的第一个应用程序。我正在尝试使用这个库来构建一个简单的计步应用程序。我做了 npm install 和 react-natvie 链接。我正在尝试以与页面上提到的库所有者相同的方式进行复制。
但我仍然收到以下错误:
TypeError: undefined is not an object (evaluating
'BMDPedometer.isStepCountingAvailable')
: This error is located at:
in StepsCounter (at App.js:26)
in App (at renderApplication.js:32)
in RCTView (at View.js:43)
in RCTView (at View.js:43)
in AppContainer (at renderApplication.js:31)
TypeError: undefined is not an object (evaluating'BMDPedometer.isStepCountingAvailable')
这是我的 StepsCounter.android.js
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import Pedometer from '@asserdata/react-native-universal-pedometer';
export default class StepsCounter extends Component{
constructor(){
Pedometer.isStepCountingAvailable((error,isAvailable)=>{
if(error) throw error;
console.log("Working");
})
}
render()
{
return(
<View>
<Text> Brooooo</Text>
</View>
);
}
}
这是我的 App.js
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View,AppRegistry} from 'react-native';
import ReactNative from 'react-native';
import Pedometer from '@asserdata/react-native-universal-pedometer';
import StepsCounter from './components/stepscounter';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
type Props = {};
export default class App extends Component<Props> {
render() {
return (
<StepsCounter/>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
// ReactNative.AppRegistry.registerComponent('StepsCounter',()=> App);