Xcode-如何为不同的构建配置设置不同的包标识符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40107908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode- how to set different bundle identifiers for different build configuration?
提问by Rashmi Ranjan mallick
I have 3 different build configurations set up for my iOS Xcode project.
我为我的 iOS Xcode 项目设置了 3 种不同的构建配置。
I want to have different bundle identifiers for different configurations for better code signing management. Below are my general identity settings, info tab settings and bundle identifier settings under build settings.
我想为不同的配置使用不同的包标识符,以便更好地进行代码签名管理。以下是我在构建设置下的一般身份设置、信息选项卡设置和包标识符设置。
INFO section-
信息部分-
BUILD SETTINGS-
构建设置-
When I update the bundle identifier directly in general section, the value in build settings --> Product Bundle Identifier gets overridden for all the build configurations.
当我直接在常规部分更新包标识符时,构建设置 --> 产品包标识符中的值将被所有构建配置覆盖。
Please suggest me a better way to manage this!!
请建议我一个更好的方法来管理这个!!
采纳答案by Jens Meder
As far as I can see, you have already setup individual xcconfig files for each configuration. That means you can just add the bundle identifier key with the corresponding value to each build configuration / xcconfig file.
据我所知,您已经为每个配置设置了单独的 xcconfig 文件。这意味着您可以将带有相应值的包标识符键添加到每个构建配置/xcconfig 文件中。
PRODUCT_BUNDLE_IDENTIFIER = com.mycomp.hockey
You need to make sure that you do not override these xcconfig settings in your Xcode project build settings (the corresponding value should not be bold).
您需要确保没有在 Xcode 项目构建设置中覆盖这些 xcconfig 设置(相应的值不应为粗体)。
If you want to switch between your bundle identifiers on the fly you might want to create one scheme per build configuration. That way you can just select the corresponding scheme in the Xcode scheme selector (next to the build/run button).
如果您想动态地在包标识符之间切换,您可能需要为每个构建配置创建一个方案。这样您就可以在 Xcode 方案选择器(在构建/运行按钮旁边)中选择相应的方案。
To create a new scheme, just select New scheme
from the scheme selector and choose a name, e.g., MyApp [Hockey]
. Then edit the scheme and select the preferred build configuration for each step, e.g., MyApp [Hockey]
for the Archive
step.
要创建新方案,只需New scheme
从方案选择器中进行选择并选择一个名称,例如,MyApp [Hockey]
。然后编辑方案并为每个步骤选择首选的构建配置,例如,MyApp [Hockey]
为该Archive
步骤选择。
You will notice that the bundle identifier on your target info screen will change depending on the selected scheme. Sometimes you need to switch to a different tab of your project settings and then back to the Info tab before the bundle identifier changes (one of many Xcode bugs).
您会注意到目标信息屏幕上的捆绑标识符将根据所选方案而变化。有时您需要切换到项目设置的不同选项卡,然后在包标识符更改(许多 Xcode 错误之一)之前返回到 Info 选项卡。
We use the exact same approach for all our projects.
我们对所有项目都使用完全相同的方法。
Hope that helps.
希望有帮助。
回答by dvdblk
Jens' answer was a bit confusing to me. All you have to do is add the xcconfig declared variable (PRODUCT_BUNDLE_IDENTIFIER = com.mycomp.hockey
) to the Info.plist
product bundle identifier field:
Jens 的回答让我有点困惑。您所要做的就是将 xcconfig 声明的变量 ( PRODUCT_BUNDLE_IDENTIFIER = com.mycomp.hockey
) 添加到Info.plist
产品包标识符字段:
Also don't forget to declare it in every xcconfig file. Enjoy.
也不要忘记在每个 xcconfig 文件中声明它。享受。