新的Firebase:动态更改数据库URL [英] New Firebase: Changing Database URL dynamically

查看:270
本文介绍了新的Firebase:动态更改数据库URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在旧的Firebase中,我曾经能够在运行时动态地获取对不同数据库的引用(例如,在dev和prod数据库之间切换,甚至切换到用户定义的数据库URL),因为数据库URL已经传递在新的Firebase中,数据库URL(以及其他设置)位于 GoogleService-Info .plist



还有可能以旧的方式做我做的事吗?还是有另一种推荐的方式来实现呢?

解决方案

好吧,无论如何我找到了答案。

  let firOptions = FIROptions(googleAppID:googleAppID),而不是通常的设置,您必须手动初始化应用程序,bundleID:bundleID,GCMSenderID:GCMSenderID,APIKey:nil,clientID:nil,trackingID:nil,androidClientID:nil,databaseURL:databaseURL,storageBucket:nil,deepLinkURLScheme:nil)$ b $ FIRApp.configureWithOptions(firOptions)

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

有关 configureWithName:options:



的进一步文档: https://firebase.google.com/docs/reference/ios/firebaseanalytics/interface_f_i_r_app


In the old Firebase, I used to be able to get reference to different database dynamically at run time (say, switching between dev and prod db, or even switching to a user-defined database URL) because the database URL is passed in as a string when instantiating a db reference.

In the new Firebase, the database URL (along with other settings) live inside GoogleService-Info.plist.

Is it still possible to do what I did in the old way? Or is there another recommended way to achieve that?

解决方案

Well, I found the answer anyway. Instead of the usual setup, you'll have to initialize the app manually like so:

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()

You can name them too with configureWithName:options:

Further documentation on this: https://firebase.google.com/docs/reference/ios/firebaseanalytics/interface_f_i_r_app

这篇关于新的Firebase:动态更改数据库URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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