Search code examples
iosxcodefirebasefirebase-analytics

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


I want to disable firebase analytics from collecting & sending events when I'm building, testing & debugging via an Xcode scheme argument, if able.

I'm aware you can edit the info.plist to disable (Firebase Docs) but would prefer a solution that doesn't require me to edit the .plist every time I'd like to switch between enabled and disabled.

Any suggestions?


Solution

  • Solution I came up with is very similar to Paul Beusterien's answer, but doesn't require a seperate scheme.

    I made a copy of my current info.plist and named it info-debug.plist. I added the required key and value to disable firebase analytics.

    FIREBASE_ANALYTICS_COLLECTION_ENABLED = 0

    info-debug screenshot

    Then I selected my scheme Testing and under Packing -> Info.plist File -> Debug I set the value to info-debug.plist

    build settings screenshot

    Anytime I build and run my app in Xcode it will use info-debug.plist because my Build Configuration is set to the default: Debug. When I archive my app it will use info.plist as set by the Build Configuration for Release.

    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 + <): scheme screenshot