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

标签 ios swift firebase firebase-realtime-database

我有一个 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/

相关文章:

ios - 为非移动开发人员构建 iPhone 应用程序的最佳移动框架?

ios - 如何在 Swift 3 中使用 NSCoder 为歌曲编码 PersistentID

objective-c - Foundation 调用 mkdir(...),它没有返回 0,并且 errno 被设置为 2

ios - 我应该在哪里声明/实例化我的 Store 对象以使其在应用程序运行时可用?

python - Firebase(客户端与服务器端)

android - 火力地堡存储 : Getting Permission denied 400 for public storage

ios - 使用 CGPoint 从图像中获取像素颜色

swift - 在 Swift 中重命名问题

closures - 为什么闭包中的 "unowned self"在 Swift 中无法正常工作?

Firebase 数据库规则 - 获取显示名称