Connect to multiple databases with Firebase

915 views
Skip to first unread message

Will G

unread,
Nov 14, 2016, 10:10:02 AM11/14/16
to Firebase Google Group
Hi,

I am having a number of difficulties with Firebase in my iOS app in Objective C.

The app used Firebase for a custom login database.

The login database contains usernames, passwords and expiry dates.

I'm aware of Firebase Auth but that only seems to handle the login. The json containing the login information also contains a date, this date is to enable access to content in the app.

I have since introduced another connection to Firebase for realtime retrieval of data into a tableView. This is on a separate Firebase project. I am not sure how to have both databases as part of one project.

The code for the login is based on Firebase version 1.0. The app connected to Firebase via a 'webservice' url.

I have since updated to the latest release of Firebase and the login code is now broken. I have updated some of the deprecated references and cleared most of the errors.

I am experiencing errors when I run the app and attempt to login however. There is no connection to the url of the Firebase project for the login.

I have added the GoogleService-Info.plist and it only allows for one DATABASE_URL. Is it possible to have multiple DATABASE_URL's? I would like to switch between the projects when necessary.

Thanks,
Will

Ian Barber

unread,
Nov 14, 2016, 7:09:56 PM11/14/16
to Firebase Google Group
There can be multiple FirebaseApp instances. One will be initialised by default from the json file values, and the other you can create yourself, e.g.

FirebaseOptions options = new FirebaseOptions.Builder()
       .setApplicationId("1:530266078999:android:481c4ecf3253701e") // Required for Analytics.
       .setApiKey("AIzaSyBRxOyIj5dJkKgAVPXRLYFkdZwh2Xxq51k") // Required for Auth.
       .setDatabaseUrl("https://project-1765055333176374514.firebaseio.com/") // Required for RTDB.
       .build();
FirebaseApp.initializeApp(this /* Context */, options, "secondary");


// Retrieve my other app.
FirebaseApp app = FirebaseApp.getInstance("secondary");
// Get the database for the other app.
FirebaseDatabase secondaryDatabase = FirebaseDatabase.getInstance(app);
Reply all
Reply to author
Forward
0 new messages