xcodebuild pass arguments to application on iOS

会有一股神秘感。 提交于 2020-01-14 02:37:29

问题


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


回答1:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!