pixelfreak pixelfreak - 8 months ago 112
iOS Question

New Firebase: Changing Database URL dynamically

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


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)        

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