【发布时间】:2023-04-05 19:37:01
【问题描述】:
firebase@3.3.0
react-native v0.32在有wifi的安卓设备上测试
Firebase 数据库没有任何身份验证规则,它是开放式读写的。
给定以下文件结构:
|_ firebase.js
|_ actions.js
这不起作用:
firebase.js
import firebase from 'firebase'
const config = {
apiKey: "*****",
authDomain: "****",
databaseURL: "*****",
storageBucket: "*****",
}
firebase.database.enableLogging(true);
export default firebase.initializeApp(config)
actions.js
import firebase from './firebase'
export const fetchData = () => {
const Data = firebase.database().ref('some/data')
Data.on('value', (snapshot) => {
console.log("snapshot", snapshot.val()) // never printed
}, (error) => {
console.error(error)
})
}
调试输出
p:0: Browser went online.
firebase-database.js:36 p:0: Listen called for /some/data default
firebase-database.js:36 p:0: Making a connection attempt
没有别的……
这确实有效(但不是解决方案):
firebase.js
...same content as above...
export default () => firebase.initializeApp(config) // we export a function instead to trigger the initialization when the app is ready
actions.js
...same content as above...
const Data = firebase().database().ref('some/data') // we "manually" trigger the initialization, it's obviously not a good solution since we can't initialize the app multiple times
输出
p:0: Browser went online.
firebase-database.js:36 p:0: Listen called for /some/data default
firebase-database.js:36 p:0: Making a connection attempt
firebase-database.js:36 p:0: Auth token refreshed
firebase-database.js:36 getToken() completed. Creating connection.
firebase-database.js:36 c:0:0: Connection created
我在这里做错了什么?我还注意到,一旦我import firebase from 'firebase',firebase 变量在导入语句中不是firebase var 的所有文件中全局可用(我可以写import FooBar from 'firebase',firebase 全局变量是仍然进口)
【问题讨论】:
-
你试过关闭调试模式吗?我有类似的问题,但它只发生在调试模式。
-
我确实打开了调试模式,因为什么都没发生,所以很遗憾不是那样。
-
您没有做错任何事情,最新的 firebase 和 react-native 之间出现了问题(这可能是正常的,但似乎没有在任何地方记录)。为我工作了“firebase”:“^3.1.0”,“react”:“15.2.1”,“react-native”:“^0.29.0”。
-
好的,谢谢!不知道我应该在哪里发布问题......
-
@Pcriulan 您可以尝试不同的依赖组合,看看哪个最先中断。我实际上已经开始这样做了,但是 npm 缓存问题使得我花了很长时间才能投入到它上面。
标签: firebase react-native firebase-realtime-database react-native-android