在单个应用中使用多个Firebase数据库 - Swift

tst*_*eve 10 ios firebase swift firebase-realtime-database

我有一个firebase数据库,目前通过GoogleService-Info.plist等连接到我的应用程序.它运行良好.

我想将我的应用程序连接到第二个firebase数据库.

它看起来像这个问题解决了针对Android 在这里.

知道如何在Xcode中使用Swift添加第二个firebase数据库吗?

编辑:我尝试了几种方法,包括使用FIROptions设置数据库的实例.我似乎无法正确构造代码.任何帮助表示赞赏!

Mik*_*ald 11

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

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
Run Code Online (Sandbox Code Playgroud)

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

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