Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
136 views
in Technique[技术] by (71.8m points)

ios - In new Firebase, how to use multiple config file in xcode?

Hey I am playing with the new firebase iOS SDK, in my project, I have only one target, I created two configurations, Debug and Release, with different bundler identifier, but seems like the config file downloaded from firebase only support one bundle identifier.

So anyone know how to use firebase within a multiple bundle identifier xcode project?

Thanks!

question from:https://stackoverflow.com/questions/37472090/in-new-firebase-how-to-use-multiple-config-file-in-xcode

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...