Reputation: 61
Is there a way a single iOS app build can report to two Firebase projects at the same time? I want to send events to my own personal Firebase account and my client's Firebase account simultaneously, from the same build.
I've investigated using Google Tag Manager to solve this, but with no success.
Upvotes: 6
Views: 1004
Reputation: 4037
If you want to initialize Firebase app into multiple projects individually. You need to first create a Firebase options object to hold the configuration data for the Firebase application. Full documentation for the options can be found in the API reference documentation for the following classes:
iOS: FirebaseOptions init
// Configure with manual options.
let secondaryOptions = FirebaseOptions.init(googleAppID: "1:27992087142:ios:2a4732a34787067a", gcmSenderID: "27992087142")
secondaryOptions.bundleID = "com.google.firebase.devrel.FiroptionConfiguration"
secondaryOptions.apiKey = "AIzaSyBicqfAZPvMgC7NZkjayUEsrepxuXzZDsk"
secondaryOptions.clientID = "27992087142-ola6qe637ulk8780vl8mo5vogegkm23n.apps.googleusercontent.com"
secondaryOptions.databaseURL = "https://myproject.firebaseio.com"
secondaryOptions.storageBucket = "myproject.appspot.com"
More details here.
Upvotes: 1
Reputation: 802
It should be possible.
Have a look at this post from the Firebase blog. The same principle applies to all platforms but the iOS specific stuff is at the bottom.
By the looks of it, this is an example of the briefest (iOS) code you'd need:
// Alt: load from plist using |FIROptions(contentsOfFile:)|
let options = FIROptions(googleAppID: googleAppID, bundleID: bundleID, GCMSenderID: GCMSenderID, APIKey: nil, clientID: nil, trackingID: nil, androidClientID: nil, databaseURL: databaseURL, storageBucket: nil, deepLinkURLScheme: nil)
FIRApp.configure(withName: "secondary", options: fileopts)
guard let secondary = FIRApp.init(named: "secondary")
else { assert(false, "Could not retrieve secondary app") }
let secondaryDatabase = FIRDatabase.database(app: secondary);
Upvotes: 1