Is there a way I can pass variables to my iOS application unit tests via command line and xcodebuild? Use case: I have setup Travis CI and want to pass sensitive data (nobody should see it) to my tests. But my project is 100% open source
I ended up with this solution:
xcodebuild -workspace "..." -scheme "..." -sdk "..." -destination "..." -configuration Release SECRET_ARG1="$SECRET_VALUE1" SECRET_ARG2="$SECRET_VALUE2" build test;
Then in test target build settings add these values:
Finally, you can access your values using macro:
#define STRINGIZE(x) #x
#define STRINGIZE2(x) STRINGIZE(x)
Now, this will resove as NSString constant:
@STRINGIZE2(SECRET_ARG1);
When building with Travis CI you can pass your secret values to environment using project settings, or encrypt and place them inside your travis.yml file (second way is more flexible and allows you to use different secret values inside one travis.yml file, but it's not so fast and convenient)
来源:https://stackoverflow.com/questions/40235209/xcodebuild-pass-arguments-to-application-on-ios