ios - 从另一个 Firebase 应用获取 Firebase 数据库
问题描述
如何从swift5中的另一个firebase应用程序访问firebase数据库?我们在一个帐户中有两个应用程序,一个是司机应用程序和骑手应用程序。我将数据存储在驾驶员实时数据库中,并希望在骑手应用程序中访问该数据库。让我知道是否有人有此解决方案。
解决方案
这是在单个 iOS 应用程序中使用多个 Firebase 数据库的代码
func initDatabase() {
FIRDatabase().database() // gets you the default database
let options = FIROptions(googleAppID: bundleID: , GCMSenderID: , APIKey: , clientID: , trackingID: , androidClientID: , databaseURL: "https://othernamespace.firebaseio.com", storageBucket: , deepLinkURLScheme: ) // fill in all the other fields
FIRApp.configureWithName("anotherClient", options: options)
let app = FIRApp(named: "anotherClient")
FIRDatabase.database(app: app!) // gets you the named other database
}
或者你可以从另一个命名的 plist 而不是一个巨大的构造函数初始化:
let filePath = NSBundle.mainBundle().pathForResource("Second-GoogleService-Info", ofType:"plist")
let options = FIROptions(contentsOfFile:filePath)
推荐阅读
- react-native - 如何在组件以反应原生方式安装时为视图设置动画?
- ios - 构建时在 xcode 中出错 - PhaseScriptExecution 失败,退出代码为非零
- r - GRU(门控循环单元)出现错误,导致生成器函数的数据用完,并且没有为 R(RStudio)中的“每个键输入..”提供数据
- mysql - 显示每种类型的电影数量
- ruby-on-rails - 错误:找不到有效的 gem 'rails' (>= 0),原因如下:在 docker 容器内
- xamarin - 如何在 Rider 中设置 Xamarin.ios 视图的属性?(如何更新自动生成的 View.designer.cs?)
- bash - 在 bash 中启动后台进程时捕获 pid
- amazon-web-services - 在 SageMaker 中隐藏密钥(环境变量?)
- neo4j - Neo4J 聚合计数全局而不是每个子图
- javascript - 匹配保留的单字符转义序列并逐字打印