简体   繁体   English

从不同的目标获取 Bundle ID

[英]Get Bundle ID from a different target

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.在我的 Xcode 项目中,我有 4 个不同的方案(prod、dev、staging、staging2),它们更改了安装到手机的应用程序的包标识符。 That way I can have all 4 versions installed side by side, similar to this technique .这样我就可以并排安装所有 4 个版本,类似于这种技术

Now I'm building a Today Extension for iOS 8. It's a new Target requiring its own bundle identifier.现在我正在为 iOS 8 构建 Today 扩展。这是一个需要自己的包标识符的新目标。

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

In this case, the Embedded Binary Bundle Identifier must be com.company.app.staging.TodayExtension .在这种情况下,嵌入式二进制包标识符必须是com.company.app.staging.TodayExtension

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?有没有一种方法可以通过首先查看父目标的捆绑标识符来配置我的 Today Extension 目标以设置其捆绑标识符? Perhaps through a custom Run Script Build Phase?也许通过自定义运行脚本构建阶段?

The build settings of the targets are not available for the other targets.目标的构建设置不可用于其他目标。 However the build settings of the PROJECT are available.但是,项目的构建设置可用。

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.因此,您可以在项目中添加用户定义的构建设置并将其命名为 PARENT_APP_BUNDLE_IDENTIFIER 并为所有方案设置正确的包 ID。

Then in the info tab of the app extension target set the bundle id to然后在应用扩展目标的信息选项卡中将捆绑 ID 设置为

$(PARENT_APP_BUNDLE_IDENTIFIER).$(PRODUCT_NAME:rfc1034identifier)

It worked perfectly fine for me.它对我来说非常好。

I have Siri extension and multiple targets, so to avoid duplicating extension for every target I added pre-action to every scheme that changes the BundleId of the extension's plist before build:我有 Siri 扩展和多个目标,因此为了避免为每个目标重复扩展,我在构建之前将预操作添加到每个更改扩展 plist 的 BundleId 的方案中:

  1. Select 'Edit scheme'选择“编辑方案”
  2. Click triangle near 'Build'单击“构建”附近的三角形
  3. Choose 'Pre-actions'选择“预行动”
  4. Click '+', choose 'New Run Script Action'单击“+”,选择“新建运行脚本操作”
  5. Choose target to provide build settings from选择目标以提供构建设置
  6. In script field paste following with your BundleId and extension folder在脚本字段中粘贴您的 BundleId 和扩展文件夹
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier 
YourDesiredBundleId" "$PROJECT_DIR/YourExtensionFolder/Info.plist"

And it works like a charm!它就像一个魅力! You need to configure it for every scheme.您需要为每个方案配置它。

In my project I need to build different versions of apps (differ in details, eg each application is branded with a different logo).在我的项目中,我需要构建不同版本的应用程序(细节不同,例如每个应用程序都带有不同的标志)。

Let's say there is about 10 "app" targets, I can't imagine adding Notification Content and Notification Service extensions per each main target (in this case I would maintaining 30 targets in total - madness).假设有大约 10 个“应用程序”目标,我无法想象为每个主要目标添加通知内容和通知服务扩展(在这种情况下,我总共会维护 30 个目标 - 疯狂)。

I run a script ( https://gist.github.com/damian-rzeszot/0b23ad87e5ab5d52aa15c095cbf43c59 ) after "Embed App Extensions" phase.我在“嵌入应用程序扩展”阶段后运行一个脚本( https://gist.github.com/damian-rzeszot/0b23ad87e5ab5d52aa15c095cbf43c59 )。 It overrides bundle id in app extension plists and re-signs the bundle.它覆盖应用程序扩展 plist 中的包 ID 并重新签名包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM