在新的Firebase中,如何在xcode中使用多个配置文件? [英] In new Firebase, how to use multiple config file in xcode?

查看:360
本文介绍了在新的Firebase中,如何在xcode中使用多个配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在玩新的firebase iOS SDK,在我的项目中,我只有一个目标,我创建了两个配置,调试和发布,具有不同的捆绑标识符,但似乎从firebase下载的配置文件只支持一个bundle标识符。

那么任何人都知道如何在一个多包标识符的xcode项目中使用firebase?

谢谢!

解决方案

更新:请参阅Firebase官方文档。 /firebase.google.com/docs/configure/#support_multiple_environments_in_your_ios_applicationrel =nofollow noreferrer> https://firebase.google.com/docs/configure/#support_multiple_environments_in_your_ios_application



使用更简单的解决方案进行更新:

  1。为GoogleService-Info.plist 
保留相同的名称2.将一个GoogleService-Info.plist放在子文件夹中,比如说暂存
3.在Xcode中添加对两个文件的引用,同时将它们链接到相应的文件目标
4.只需在你的AppDelegate中使用FIRApp.configure(),完成






我的第一次尝试没有解决问题:

我重命名了第二个GoogleService-Info。 JSON到其他东西,并使用以下代码从AppDelegate配置Firebase。

  // 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)

如果我运行暂存目标, Firebase关于'找不到配置文件:'GoogleService-Info.plist''的抱怨。但之后它会显示Firebase Analytics v.300000开始。



当我在Firebase仪表板上进行检查时,生产和临时应用程序都会记录传入的用户事件。

上面提到的configureWithOptions方法在Firebase文档中没有记录,我通过检查它的源代码来了解它。我不确定调用它的缺点是什么。我很乐意听取其他方法。


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!

解决方案

Update: see Firebase official documentation https://firebase.google.com/docs/configure/#support_multiple_environments_in_your_ios_application

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.

这篇关于在新的Firebase中,如何在xcode中使用多个配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆