在单个应用程序中使用多个Firebase数据库 - Swift [英] Use more than one Firebase database in single app - Swift

查看:136
本文介绍了在单个应用程序中使用多个Firebase数据库 - Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Firebase数据库,当前连接到我的应用程序与GoogleService-Info.plist等等。它工作的很棒。

我想连接我的应用程序第二个firebase数据库以及。

它看起来像这个问题已经解决了Android 连接到多于一个firebase-database-from-an-android-app>



任何想法如何在Xcode中添加Swift的第二个firebase数据库?编辑:我已经尝试了几种方法,包括使用FIROptions设置数据库的一个实例。我似乎无法正确构建代码。任何帮助表示赞赏!

解决方案

初始化另一个数据库的正确方法是使用 FIROptions 构造函数,如下所示:

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ FIRDatabase b
let options = FIROptions(googleAppID:bundleID:,GCMSenderID:,APIKey:,clientID:,trackingID:,androidClientID:,databaseURL:https://othernamespace.firebaseio.com,storageBucket:,deepLinkURLScheme:) //填写所有其他字段
FIRApp.configureWithName(anotherClient,options:options)
let app = FIRApp(named:anotherClient)
FIRDatabase.database(app:app !)//得到你命名的其他数据库

或者你可以从另一个命名plist初始化而不是巨大的构造函数:
$ b

  let filePath = NSBundle.mainBundle()。pathForResource(MyCool-GoogleService-Info,ofType:plist )
让options = FIROptions(contentsOfFile:fileP ath)


I have a firebase database currently connected to my app with the GoogleService-Info.plist, etc. It works great.

I would like to connect my app to a second firebase database as well.

It looks like this problem was solved for Android here.

Any idea how to add a second firebase database with Swift in Xcode?

EDIT: I have tried several approaches, including using FIROptions to set up an instance of a database. I just can't seem to structure the code correctly. Any help is appreciated!

解决方案

The proper way to initialize another database is to initialize another app, using the FIROptions constructor, like so:

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

Or you can initialize from another named plist rather than a huge constructor:

let filePath = NSBundle.mainBundle().pathForResource("MyCool-GoogleService-Info", ofType:"plist")
let options = FIROptions(contentsOfFile:filePath)

这篇关于在单个应用程序中使用多个Firebase数据库 - Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆