有没有办法用 Xcode 中的方案参数禁用 firebase 分析?

Is there a way to disable firebase analytics with a scheme argument in Xcode?

我想在构建、测试和调试时通过 Xcode 方案参数禁用 firebase 分析收集和发送事件,如果可以的话。

我知道您可以编辑 info.plist 以禁用 (Firebase Docs),但我更喜欢不需要我每次都编辑 .plist 的解决方案在启用和禁用之间切换。

有什么建议吗?

您可以将两个不同的 plist 配置到两个不同的构建目标中,每个都有一个关联的方案。

详情here.

我提出的解决方案与 Paul Beusterien 的回答非常相似,但不需要单独的方案。

我复制了当前的 info.plist 并将其命名为 info-debug.plist。我添加了禁用 firebase 分析所需的键和值。

FIREBASE_ANALYTICS_COLLECTION_ENABLED = 0

然后我选择了我的方案 Testing 并在 Packing -> Info.plist File -> Debug 下我将值设置为 info-debug.plist

任何时候我在 Xcode 中构建和 运行 我的应用程序时,它都会使用 info-debug.plist,因为我的 Build Configuration 设置为默认值:Debug。当我存档我的应​​用程序时,它将使用 Build ConfigurationRelease 设置的 info.plist

https://medium.com/geekculture/what-are-debug-and-release-modes-in-xcode-how-to-check-app-is-running-in-debug-mode-8dadad6a3428

Debug vs Release Mode

When you create a new project in Xcode, it defines two build configurations, Debug and Release. By default, Debug configuration is used during development whereas the Release configuration is used for TestFlights or App Store. In other words, when you run the app on the simulators or real devices by hitting the Run button(cmd + R), your app is running with Debug configuration, aka Debug mode; when you archive and upload a build to App Store Connect, app is running in Release mode. However, this is just the default behavior. Technically, you can run apps on simulators in any mode you want. It’s also true for archiving(builds that you upload to the App Store Connect). To change build configurations for development and archiving, you can go to Product → Scheme → Edit Scheme(Command + <):