我正在运行Even Bacon中的一个react-native
聊天应用示例。我可以成功输入我的名字。但是,当我输入聊天消息时,我收到有关firebase
的警告,表明该聊天消息未被接收:
这里是Chat.js
:
import React, { Component} from 'react';
import {View, StyleSheet } from 'react-native';
import { GiftedChat } from 'react-native-gifted-chat';
import Fire from '../Fire';
class Chat extends React.Component {
static navigationOptions = ({ navigation}) => ({
title: (navigation.state.params || {}).name || 'Chat!',
});
state = {
messages: [],
};
componentDidMount() {
Fire.shared.on(message =>
this.setState(previousState => ({
messages: GiftedChat.append(previousState.messages, message),
}))
);
}
componentWillUnmount() {
Fire.shared.off();
}
get user() {
// return our name and our UID for GiftedChat to parse
return {
name: this.props.navigation.state.params.name,
_id: Fire.shared.uid,
};
}
render() {
return (
<GiftedChat
messages={this.state.messages}
onSend={Fire.shared.send}
user={this.user}
/>
);
}
}
const styles = StyleSheet.create({});
export default Chat;
答案 0 :(得分:1)
确保您已设置像这样的数据库规则
{
"rules": {
".read": true,
".write": true
}
}