Search code examples
androidiosdeploymentconfigurationtestflight

How to keep Staging analytics/data out of Production for App Store deployment


Once a build is submitted to the Apple Store/TestFlight or Google Play, that specific build can't be changed.

I take that to mean a Production build must be submitted, configured for the Production environment.

But then how would that same build be able to point to a Staging environment (for TestFlight or Google Play Alpha/Beta testing)? and then when approved reconfigured to point to Production before promotion to the App Store?

How do I support both a Staging and Production environment in a single build?

An example, would be for analytics where staging metrics shouldn't go to production or Q/A users whose data should reside on a Staging database.


Solution

  • There are different approaches to deal with this. Part of this depends on your needs. For example, if you want to to be able to point to stage with a production build.

    An easy approach is to use the Debug and Release configurations as your means of separating the two. In other words, builds built using the Debug configuration will point to stage and builds built with Release point to prod.

    You can certainly pimp this out if you want. For example, you can have your Debug build actually be configurable to change environments.

    Control of this is done with compile time flags such as DEBUG. So your code would be something like:

    #if DEBUG
        // Do Staging environment setup here
    #else
        // Do Prod environment setup here
    #endif
    

    It can be helpful to do this through some object to limit the places in code you need to discern between environments.

    Note this is also a common way of handling 3rd Party services you may use for analytics, etc which have different keys for QA/prod.