xcodebuild 将参数传递给 iOS 上的应用程序 [英] xcodebuild pass arguments to application on iOS

查看:21
本文介绍了xcodebuild 将参数传递给 iOS 上的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过命令行和 xcodebuild 将变量传递给我的 iOS 应用程序单元测试?用例:我已经设置了 Travis CI 并希望将敏感数据(没有人应该看到它)传递给我的测试.但我的项目是 100% 开源的

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"构建测试;

然后在测试目标构建设置中添加这些值:

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)

现在,这将解析为 NSString 常量:

Now, this will resove as NSString constant:

@STRINGIZE2(SECRET_ARG1);

当使用 Travis CI 构建时,您可以使用项目设置将您的秘密值传递给环境,或者将它们加密并将其放置在您的 travis.yml 文件中(第二种方式更灵活,允许您在一个 travis.yml 中使用不同的秘密值文件,但它不是那么快速和方便)

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)

这篇关于xcodebuild 将参数传递给 iOS 上的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆