Objective-C – Having a TestFlight configuration to

2020-07-20 03:27发布

问题:

I've followed the instructions from TestFlight to duplicate the "release" configuration. Also I'm using TestFlight SDK to get live reports from my app. By doing this I had to include some TestFlight code in my application. Of course I don't want to have this code in my release version of my app.

Is there some way to only include this code in the testflight configuration (the duplicated release configuration)? The same way you can do with #ifdef DEBUG for the debug configuration (or do I have to create a separate target for this and only include the TestFlight SDK in that target?)

回答1:

You can exclude code from running using #ifdef statements pretty easily, as we suggest it for our HockeyApp service here: http://support.hockeyapp.net/kb/client-integration/crash-reporting-on-ios-quincykit

Basically it is:

  1. Add a preprocessor macro to your Xcode project for all configurations: CONFIGURATION_$(CONFIGURATION)

  2. Then you will be able to use these lines of code to include code only for a specific configuration:

    #if defined (CONFIGURATION_Beta)
        // YOUR CODE
    #endif
    
  3. This replace Beta with the name of your configuration that should include the code only

The link above provides images and more detailed text on how to do it. Since you will use that library only in your beta distribution configuration, you don't need to create another configuration besides the already created one for beta distribution.

You need to have one configuration for debug, which is for development, one for beta distribution to set the adhoc entitlements and one for app store distribution. The last two are usually variations of the release configuration.



回答2:

I think you'd have to create a separate build configuration and use something like #ifdef TESTFLIGHT. You should add a macro for that configuration so it's defined only for the TestFlight configuration.



回答3:

My solution to this is to have a separate branch in Git for the Testflight version which includes the SDK and calls in the code, headers, etc.

I then do all my work on the main branch and keep the Testflight branch up to date with these changes. That way I don't have to include libraries or headers that I don't use in my shipping version.

It's simpler than it sounds.