问题:
我正在创建具有Firebase集成的EXPO应用程序。在其中,我创建了一个配置文件以与数据库连接。这就是它的样子。
import Firebase from 'firebase';
let config = {
apiKey: "mykey",
authDomain: "mytrain-5beba.firebaseapp.com",
databaseURL: "https://mytain-5beba.firebaseio.com",
projectId: "mytain-5beba",
storageBucket: "mytain-5beba.appspot.com",
messagingSenderId: "myid"
};
let app = Firebase.initializeApp(config);
export const db = app.database();
在服务文件夹中,我已经创建了一个服务文件来处理诸如此类的操作。这样看起来。
从'../config/db'导入{db};
export const addItem =(item)=> { db.ref('/ tains')。push({ 名称:物品 }); }
在我的组件中,在componentDidMount方法中,我已经做了类似的事情来测试天气数据库连接是否正常工作。
import React, { Component } from "react";
import {
StyleSheet,
Text,
TextInput,
View,
TouchableOpacity,
Dimensions,
Picker,
ListView
} from "react-native";
import {
Ionicons,
Foundation,
Entypo,
MaterialCommunityIcons,
FontAwesome,
MaterialIcons
} from "@expo/vector-icons";
import { Autocomplete } from "react-native-autocomplete-input";
import { addItem } from '../../services/stationService';
const { height, width } = Dimensions.get("window");
const box_width = width / 2 + 40;
export default class TicketForm extends React.Component {
constructor(props) {
super(props);
this.state = {
name: ""
};
}
static navigationOptions = {
title: "",
headerStyle: {
backgroundColor: "#2b78fe"
},
headerTintColor: "#fff",
headerTitleStyle: {
color: "#ffff"
}
};
componentDidMount() {
const name = "Tharindu";
addItem(name);
}
render() {
return (
<View>
<Text>Haiii</Text>
</View>
);
}
}
});
当我运行expo时,请启动--android。它向我显示了一些这样的警告。
[15:52:56] [2018-11-05T10:22:51.070Z] @firebase/database:, FIREBASE WARNING: set at /station/-LQYOMpnDzgdkj25XUDQ failed: permission_denied
- node_modules\react-native\Libraries\ReactNative\YellowBox.js:80:15 in warn
- node_modules\expo\src\Expo.js:26:41 in warn
- ... 20 more stack frames from framework internals
[15:53:01] [Unhandled promise rejection: Error: PERMISSION_DENIED: Permission denied]
- node_modules\@firebase\database\dist\index.cjs.js:13076:45 in <unknown>
- node_modules\@firebase\database\dist\index.cjs.js:690:8 in exceptionGuard
- ... 18 more stack frames from framework internals
[15:53:04] Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info.
(Saw setTimeout with duration 360595ms)
- node_modules\react-native\Libraries\ReactNative\YellowBox.js:80:15 in warn
- node_modules\expo\src\Expo.js:26:41 in warn
- ... 11 more stack frames from framework internals
[15:59:03] Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info.
(Saw setTimeout with duration 92226ms)
- node_modules\react-native\Libraries\ReactNative\YellowBox.js:80:15 in warn
- node_modules\expo\src\Expo.js:26:41 in warn
- ... 11 more stack frames from framework internals
我对这些本机和firebase东西很陌生。有人可以帮我解决这个问题。谢谢!
答案 0 :(得分:1)
打开firebase,在左侧选择数据库。 现在,在右侧,从下拉列表中选择[实时数据库],然后将规则更改为:
{
"rules": {
".read": true,
".write": true
}
}
有效.. !!