【发布时间】:2019-02-18 10:51:12
【问题描述】:
我正在构建一个简单的 Android 应用程序。我现在正试图让我的手机每 3 秒振动一次。这是我的代码:
componentDidMount() {
BackgroundTimer.runBackgroundTimer(() => {
Vibration.vibrate(1000);
}, 3000);
}
componentWillUnmount() {
BackgroundTimer.stopBackgroundTimer();
}
render() {
return (
<View style={styles.container}>
<ScrollView>
{this.state.errors.map(e => {
const {error, solved, errorInfo, key, uid, date} = e;
return (
<View key={e.key} style={{backgroundColor: solved === true ? 'green' : '#ff5b68'}}>
<Text>{error}</Text>
<Text>{errorInfo}</Text>
<Text>{key}</Text>
<Text>{uid}</Text>
<Text>{date}</Text>
<MarkedAsSolvedButton id={key} solved={solved}/>
</View>
)
})}
</ScrollView>
</View>
);
}
但我收到一个错误:
TypeError: TypeError: undefined is not an object (evalating 'RNBackgroundTimer.start')
我错过了什么?
我正在使用这个模块:https://github.com/ocetnik/react-native-background-timer
【问题讨论】:
-
你运行 react-native 链接了吗?
-
如果你在 ios 上测试它,那么请检查 pod!
-
我确实链接了它。我正在 Android 上测试它
-
然后检查 build.gradle 看看是否包含实现和项目链接?请在你的原生安卓代码中
-
我以前从未从事过 Android 开发工作。我在找什么?
标签: android react-native