我在Android上使用@ react-native-firebase / database来存储数据的应用程序。在第一天,我能够从Firebase存储和检索数据,但是在第二天的第二天,似乎什么也没起作用。当我创建对数据库上现有对象的引用以检索数据时,即使我将数据手动存储在数据库的Firebase控制台中,它也不会检索数据。当我使用相同的引用存储数据时,它不会将该数据存储到Firebase控制台,但是可以在那时检索该数据。这是暂时的。这意味着,当我将某些数据存储到某个引用时,只要不重新启动该应用程序,它们就会被临时存储并可以检索。重新启动应用程序后,数据消失了。它永远不会显示在Firebase控制台中。建议任何解决方法。提前致谢。 这是我存储和检索数据的代码。 Firebase云存储工作正常。 反应本机版本0.63.2 @ react-native-firebase /数据库版本7.5.1
//code to store data
import * as React from 'react';
import {
Text,
View,
StyleSheet,
TextInput,
TouchableOpacity,
} from 'react-native';
import {Picker} from '@react-native-community/picker';
import Icon from 'react-native-vector-icons/Feather';
import database from '@react-native-firebase/database';
class UploadScreen extends React.Component {
state = {
sem: null,
branch: null,
subject: null,
year: null,
pic: 'mg',
};
uploadObject() {
const databaseRef = database().ref('users');
console.log(databaseRef);
const sendObj = databaseRef.push().set({
sem: this.state.sem,
branch: this.state.branch,
subject: this.state.subject,
year: this.state.year,
});
}
//code to retrieve the data
import * as React from 'react';
import {
Text,
View,
StyleSheet,
TextInput,
TouchableOpacity,
} from 'react-native';
import {Picker} from '@react-native-community/picker';
import database from '@react-native-firebase/database';
import Icon from 'react-native-vector-icons/Feather';
class HomeScreen extends React.Component {
state = {
sem: null,
branch: null,
subject: null,
year: null,
collected: [],
};
componentDidMount() {
const myref = database().ref('users');
console.log(myref);
myref.on('value', (snapshot) => {
console.log(snapshot.val());
});
}