如何将扩展的包 ID 作为环境变量传递 [英] How to pass bundle id of extension as environment variable

查看:25
本文介绍了如何将扩展的包 ID 作为环境变量传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过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).

另一种方法见下文.

如何加载父项目设置的前缀?

  1. 创建一个 .xcconfig 文件(内容类似于示例).
  2. 在项目设置的 Info 选项卡(不是目标的 Info 选项卡)中设置 .xcconfig 文件.
  3. 在目标的 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)

<块引用>

注意:

  1. 您想使用一些环境作为前缀,但在上面我使用 PRODUCT_NAME 作为后缀(只需根据需要进行编辑).
  2. mylib.xcconfig 文件设置了 MYLIB_BUNDLE_PREFIX,并且在我的 MyLib.xcodeproj 文件目录之外(所以在父项目的 config 目录,我在 MyLib 的 README.md 中描述用户应该在那里创建它.
  3. 因此,除了展示我的 #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?

  1. Create an .xcconfig file (with content like example).
  2. Set up the .xcconfig file in project settings's Info tab (not target's Info tab).
  3. In target's Build Settings tab, ensure PRODUCT_BUNDLE_IDENTIFIER is not bold (click it and press delete).

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:

  1. You want to use some environment as prefix, but above I use PRODUCT_NAME as suffix (simply edit as you wish).
  2. The mylib.xcconfig file sets MYLIB_BUNDLE_PREFIX, and is outside of my MyLib.xcodeproj file's directory (so is in parent project's config directory, I describe in MyLib's README.md that users should create it there).
  3. So, beside showing my #include approache, I try to introduce use of environment-variable.

这篇关于如何将扩展的包 ID 作为环境变量传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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