新Firebase:动态更改数据库URL

时间:2016-05-27 21:16:48

标签: ios swift firebase

在旧的Firebase中,我曾经能够在运行时动态引用不同的数据库(例如,在dev和prod db之间切换,甚至切换到用户定义的数据库URL),因为数据库URL已通过在实例化db引用时作为字符串。

在新的Firebase中,数据库网址(以及其他设置)位于GoogleService-Info.plist内。

是否仍然可以按照旧方式做我所做的事情?或者是否有其他推荐的方法来实现这一目标?

1 个答案:

答案 0 :(得分:6)

好吧,无论如何我找到了答案。您需要手动初始化应用程序,而不是通常的设置:

let firOptions = FIROptions(googleAppID: googleAppID, bundleID: bundleID, GCMSenderID: GCMSenderID, APIKey: nil, clientID: nil, trackingID: nil, androidClientID: nil, databaseURL: databaseURL, storageBucket: nil, deepLinkURLScheme: nil)        
FIRApp.configureWithOptions(firOptions)

let firebaseRef = FIRDatabase.database().reference()

您也可以使用configureWithName:options:

命名

有关此问题的进一步文件:Array.prototype.forEach