如何将扩展的包 ID 作为环境变量传递 [英] How to pass bundle id of extension as environment variable
问题描述
我需要通过xcodebuild"在 Today Extension 中构建一个 Xcode 项目.bundle 的主要目标是 com.myapp,而扩展的 bundle id 是 com.myapp.todayextension.我想将包 id 作为 xcodebuild 的参数传递:我尝试用自定义环境变量(例如 ${MAIN_TARGET_BUNDLEID} 和 ${EXTENSION_BUNDLEID})替换 xcode 项目中的包 ID,但 xcodebuild 失败.你能帮我使用 xcodebuild 命令的正确语法吗?谢谢.
迟到总比不到好;我们不能直接在 General
选项卡中使用环境变量,您需要进入 Build Settings
选项卡,然后将 Product Bundle Identifier
设置为您的环境变量,例如 $(PRODUCT_NAME)
.
另一种方法见下文.
如何加载父项目设置的前缀?
- 创建一个
.xcconfig
文件(内容类似于示例). - 在项目设置的
Info
选项卡(不是目标的Info
选项卡)中设置.xcconfig
文件. - 在目标的
Build Settings
选项卡中,确保PRODUCT_BUNDLE_IDENTIFIER
不是粗体(单击它并按delete
).
但是 Podfile
用户还应该看到:如何让 Xcode 使用多个 xcconfig 文件?
示例
我的 extension.xcconfig
文件(在 MyApp/MyLib/MyExtension
目录中),看起来像:
//下面加载 `MyApp/config/mylib.xcconfig` 文件.#include "../../config/mylib.xcconfig";PRODUCT_BUNDLE_IDENTIFIER = $(MYLIB_BUNDLE_PREFIX).$(PRODUCT_NAME)
<块引用>
注意:
- 您想使用一些环境作为前缀,但在上面我使用
PRODUCT_NAME
作为后缀(只需根据需要进行编辑). mylib.xcconfig
文件设置了MYLIB_BUNDLE_PREFIX
,并且在我的MyLib.xcodeproj
文件目录之外(所以在父项目的config
目录,我在 MyLib 的README.md
中描述用户应该在那里创建它.- 因此,除了展示我的
#include
方法之外,我还尝试介绍环境变量的使用.
I need to build an Xcode project within a Today Extension by 'xcodebuild'. The bundle is of the main target is com.myapp, while the bundle id of the extension is com.myapp.todayextension. I'd like to pass both the bundle id's as parameters of xcodebuild: I tried to replace the bundle id's in the xcode project by custom environment variables (e.g. ${MAIN_TARGET_BUNDLEID} and ${EXTENSION_BUNDLEID}) but the xcodebuild fails. Could you please help me with the correct syntax of xcodebuild command ? Thanks.
Better too late than never; We can't directly use an environment variable in General
tab, you will need to go into Build Settings
tab, then set Product Bundle Identifier
to your environment-variable, for example $(PRODUCT_NAME)
.
See below for another approach.
How to load prefix set by parent project?
- Create an
.xcconfig
file (with content like example). - Set up the
.xcconfig
file in project settings'sInfo
tab (not target'sInfo
tab). - In target's
Build Settings
tab, ensurePRODUCT_BUNDLE_IDENTIFIER
is not bold (click it and pressdelete
).
But Podfile
users should see also: How to make Xcode use multiple xcconfig files?
Example
My extension.xcconfig
file (which is in MyApp/MyLib/MyExtension
directory), looks something like:
// Below loads `MyApp/config/mylib.xcconfig` file.
#include "../../config/mylib.xcconfig"
PRODUCT_BUNDLE_IDENTIFIER = $(MYLIB_BUNDLE_PREFIX).$(PRODUCT_NAME)
Note that:
- You want to use some environment as prefix, but above I use
PRODUCT_NAME
as suffix (simply edit as you wish).- The
mylib.xcconfig
file setsMYLIB_BUNDLE_PREFIX
, and is outside of myMyLib.xcodeproj
file's directory (so is in parent project'sconfig
directory, I describe in MyLib'sREADME.md
that users should create it there).- So, beside showing my
#include
approache, I try to introduce use of environment-variable.
这篇关于如何将扩展的包 ID 作为环境变量传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!