OGeek|极客世界-中国程序员成长平台

标题: ios - 如何读取 info.plist 中的环境变量? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 01:08
标题: ios - 如何读取 info.plist 中的环境变量?

我正在终端中设置一个变量

export VAR=1.0.0

我必须将它从 ~/.bash_profile 读取到 info.plist 中,例如:

<key>CFBundleShortVersionString</key>
<string>VAR</string>

这样我就可以进行自动化构建了。有没有办法读取变量?



Best Answer-推荐答案


info.plist 中引用变量:

<key>CFBundleShortVersionString</key>
<string>$(VAR)</string>

然后,当您从终端构建项目时,您会为 VAR 注入(inject)值:

xcodebuild build VAR=123 -project myProject.xcodeproj -target myTarget -sdk iphonesimulator

或者如果环境中设置的变量:

xcodebuild build VAR=${VAR} -project myProject.xcodeproj -target myTarget -sdk iphonesimulator

关于ios - 如何读取 info.plist 中的环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43513152/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4