Update: see Firebase official documentation
https://firebase.google.com/docs/projects/multiprojects
Updated with an easier solution:
1. keep the same names for both GoogleService-Info.plist
2. put one GoogleService-Info.plist inside a subfolder, say "staging"
3. add references to both files in Xcode while linking them to corresponding targets
4. just use FIRApp.configure() in your AppDelegate, done
My first attempt that didn't solve the issue:
I renamed the second GoogleService-Info.json to something else and used following code to configure Firebase from AppDelegate.
// Swift code
#if STAGING
let firebasePlistFileName = "GoogleService-Staging-Info"
#else
let firebasePlistFileName = "GoogleService-Info"
#endif
let firbaseOptions = FIROptions(contentsOfFile: NSBundle.mainBundle().pathForResource(firebasePlistFileName, ofType: "plist"))
FIRApp.configureWithOptions(firbaseOptions)
If I run the Staging target, I will receive Firebase's complaint about 'Could not locate configuration file: 'GoogleService-Info.plist'.'. But then it says ' Firebase Analytics v.3300000 started'.
As I checked on the Firebase dashboard, both production and staging apps have incoming user events being logged.
The above-mentioned configureWithOptions method is not documented in Firebase documentation, I figured it out by checking its source code. I'm not sure about what could be the downside of calling this. I would love to hear other approaches.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…