我有一个 firebase 数据库当前通过 GoogleService-Info.plist 等连接到我的应用程序。它运行良好。
我也想将我的应用程序连接到第二个 firebase 数据库。
看起来这个问题在 Android 上已经解决了 here .
知道如何在 Xcode 中使用 Swift 添加第二个 firebase 数据库吗?
编辑:我尝试了几种方法,包括使用 FIROptions 来设置数据库实例。我似乎无法正确构建代码。任何帮助表示赞赏!
最佳答案
初始化另一个数据库的正确方法是使用 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
或者你可以从另一个命名的 plist 而不是一个巨大的构造函数初始化:
let filePath = NSBundle.mainBundle().pathForResource("MyCool-GoogleService-Info", ofType:"plist")
let options = FIROptions(contentsOfFile:filePath)
关于ios - 在单个应用程序中使用多个 Firebase 数据库 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38363412/