从其他目标获取Bundle ID [英] Get Bundle ID from a different target
问题描述
在我的Xcode项目中,我有4种不同的方案(prod,dev,staging,staging2),它们会更改安装到手机的应用程序的包标识符。这样我可以并排安装所有4个版本,类似于这种技术。
In my Xcode project, I have 4 different schemes (prod, dev, staging, staging2) which changes the bundle identifier of the app that gets installed to the phone. That way I can have all 4 versions installed side by side, similar to this technique.
现在我正在为iOS 8构建今日扩展这是一个需要自己的捆绑标识符的新Target。
Now I'm building a Today Extension for iOS 8. It's a new Target requiring its own bundle identifier.
扩展的捆绑标识符必须以Parent App的Bundle Identifier为前缀,否则会抛出警告:
The Extension's Bundle Identifier must be prefixed with the Parent App's Bundle Identifier, or a warning is thrown:
error: Embedded binary's bundle identifier is not prefixed with the parent app's bundle identifier.
Embedded Binary Bundle Identifier: com.company.app.TodayExtension
Parent App Bundle Identifier: com.company.app.staging
在这种情况下,嵌入式二进制包标识符必须是 com.company.app.staging.TodayExtension
。
In this case, the Embedded Binary Bundle Identifier must be com.company.app.staging.TodayExtension
.
我有没有办法通过首先查看Parent目标的包标识符来配置我的Today Extension目标来设置其包标识符?也许通过自定义的运行脚本构建阶段?
Is there a way I can configure my Today Extension target to set its bundle identifier by first looking at the Parent target's bundle identifier? Perhaps through a custom Run Script Build Phase?
推荐答案
目标的构建设置不适用于其他目标。但是,可以使用PROJECT的构建设置。
The build settings of the targets are not available for the other targets. However the build settings of the PROJECT are available.
您可以在项目中添加用户定义的构建设置,并将其命名为PARENT_APP_BUNDLE_IDENTIFIER,并为所有方案设置正确的包ID。
You can thus add a user-defined build setting in your project and call it PARENT_APP_BUNDLE_IDENTIFIER and set the correct bundle id for all your schemes.
然后在应用扩展目标的信息标签中将捆绑ID设置为
Then in the info tab of the app extension target set the bundle id to
$(PARENT_APP_BUNDLE_IDENTIFIER).$(PRODUCT_NAME:rfc1034identifier)
它对我来说非常好。
这篇关于从其他目标获取Bundle ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!