javascript - React-Native-Firebase:RTDB 模拟器
问题描述
有人知道如何使用实时数据库模拟器吗?
我可以使用如下所示的功能和 Firestore 模拟器。
import functions from '@react-native-firebase/functions';
import firestore from '@react-native-firebase/firestore';
functions().useFunctionsEmulator('http://localhost:5001');
firestore().settings({ host: 'localhost:8080' });
但是无法为实时数据库找到类似的东西。任何链接/视频表示赞赏。
谢谢。
解决方案
基本上Frank van Puffelen发布的解决方案是正确的。但是,这让我陷入了一段时间,所以我将分享我的经验以节省其他人的时间。
import { firebase } from "@react-native-firebase/database";
const database = firebase
.app()
.database("http://localhost:9000?ns=YOUR_DATABASE_NAMESPACE");
const ref = database.ref(`yourPath`)
...
巨大的陷阱来了:如果您使用的是 Android Emulator,则必须使用
const database = firebase
.app()
.database("http://10.0.2.2:9000?ns=YOUR_DATABASE_NAMESPACE");
如果您使用的是真正的 android 设备,则必须先设置反向代理:
adb reverse tcp:9000 tcp:9000
然后正常设置数据库
const database = firebase
.app()
.database("http://localhost:9000?ns=YOUR_DATABASE_NAMESPACE");
我没有测试 iOS,但我相信 localhost 应该可以工作。
推荐阅读
- python - Python:用于启动独立项目的标准骨架种子
- python - 如何在 2 列上训练 ML 模型以解决分类问题?
- django - 如何在 django 单元测试中模拟 celery send_task 函数
- php - 使用数组PHP划分表数据的正确方法
- java - 在 Spring Boot 应用程序中启用 SSL
- android - java.lang.ArrayIndexOutOfBoundsException:超出范围
- parse-platform - 本地解析数据库在 SwiftUI 中出现错误
- json - 在 JQ 中删除嵌套对象中的字段
- istio - Istio 手动 sidecar 注入报错
- java - 使用生产者 - 消费者模式处理巨大的 CSV 文件