Embedded App Naming Conflict Resolved with Bundle Display Name
• 3 minute read
The app I am working on has a customizable bundle name and embeds another app which should appear with the same name. This causes a conflict which can be overcome by using CFBundleDisplayName.
The rough Xcode project structure is like this: I have a main app which runs as an agent. This means that it does not appear in the foreground or dock at all. It only places a menu bar extra in the system’s menu bar. One of the items in that menu opens an embedded app which takes over the foreground user interface tasks. Splitting this into two distinct apps is necessary because the app role cannot be switched during runtime in the way we need. In the predecessor project everything was implemented in the agent app which comes with some inconvenient problems for users. One example is the invisibility of the app in the dock but also the tricky event handling as technically it is not a user activity and thus never in the foreground.
Anyway, the agent app also has a customizable bundle name related to the service it is offering to users.
The embedded app, called “Assistant”, appears with its own bundle name in the dock.
It is of no use when “Assistant” is the label while hovering over the dock icon of the assistant app.
It consistently should reflect the main app’s bundle name to implement an experience which covers up the separate apps.
At the time of writing I only found a hacky way to achieve this.
The agent and assistant build targets cannot have the same value for the PRODUCT_NAME
build setting because it will result in name conflicts in the build directory.
multiple commands produce […]
I tried to shove the build app bundles into dedicated folders inside the build folder without success. Currently, it appears to me this is not possible with the “new” (it was introduced already some years ago) build system.
So I the remembered CFBundleDisplayName
key in Info.plist
which I stumbled upon already earlier.
This enables to define divergent or localized display names for app bundles on iOS and macOS.
From the documentation archive I learned how to make it work.
Its value must be equal to the real app bundle name in the file system to make macOS look up the localized value.
As the assistant app’s bundle name is defined by the target name, I define the CFBundleDisplayName
value equally:
$(TARGET_NAME)
Then I create an InfoPlist.strings
file in the assistant app group and localized variations for all localizations configured in the project.
This is the usual workflow when localizing access request strings (such as NSContactsUsageDescription
) which must be defined in the Info.plist
.
"CFBundleDisplayName" = "This is the localized display name!";
Now the system will use the value defined in the translation which basically can be the same as the agent’s app bundle name in all localizations.
This way the assistant app will appear with the localized CFBundleDisplayName
value instead of its real name in the file system.