Xcode14 setting Display Name does not take effect

I. Introduction

As early as Xcode13, Apple made a major reform to Info.plist. The default Info.plist file of the new OC project is "empty", and the Swift project even has no Info.plist file at all. Apple did this to create a The new Info.plist management method moves the configuration in the Info.plist physical file to Xcode buildSetting.

However, most developers (such as me) do not buy it, and still use the old Info.plist file mode, how to restore the old Info.plist file mode, and what are the disadvantages of the new mode. For more information, see my previous article " Xcode13 "Disappeared" the Info.plist file .

2. New changes in Xcode14

Xcode14 Apple made another sneaky change.

If you still use the old Info.plist file mode, you will find that setting the App name in the Xcode panel (General - Display Name) will not take effect. As shown in the picture below, we set the Display Name to "Wahaha", and you will find that the name of the App is still "TestTMP".

Before Xcode14, the Display Name value in the Xcode panel was synchronized with the CFBundleDisplayName field of the Info.plist physical file in the project.

Starting from Xcode14 , the Display Name value in the Xcode panel is no longer synchronized with the CFBundleDisplayName field of the Info.plist physical file, but with the value of Build Setting - Info.plist Values ​​(new module) - Bundle Display Name (as shown below) .

Note: This is not affected by the Generate Info.plist File switch (described below), the switch only affects the generation mode of the Info.plist file. That is, no matter whether the switch is YES or NO, the Display Name value in the Xcode panel is taken from Build Setting - Info.plist Values ​​- Bundle Display Name.

1. Generate Info.plist File field

Build Settings - Generate Info.plist File (GENERATE_INFOPLIST_FILE) This field is newly introduced by Xcode13, it indicates whether to enable the new mode of generating Info.plist file, YES starts, NO does not enable. This field defaults to YES for new projects, and NO for old projects.

When the value is YES, Xcode uses the new Info.plist file generation mode. Xcode will take data from Build Setting - Info.plist Values ​​module and Info - Custom iOS Target Properties to generate the final Info.plist file when packaging .

When the value is NO, Xcode uses the old Info.plist file generation mode. We only need to configure parameters in the Info.plist physical file in the project as before, and Xcode will read the configuration in the Info.plist physical file to generate the Info.plist file in the final package body when packaging.

2. The reason for the problem that the Display Name does not take effect

First of all, let's make it clear: the name of the App is ultimately determined by the CFBundleDisplayName field in the Info.plist file in the compiled package body . If there is no CFBundleDisplayName field in the Info.plist, the value of the CFBundleName field will be taken.

Due to the new features of Xcode14, the Display Name set in the Xcode panel will only be synchronized to Build Setting - Info.plist Values ​​- Bundle Display Name .

Since we used the old Info.plist file mode (that is, the value of BuildSetting - Generate Info.plist File is NO), the settings of BuildSetting - Info.plist Values ​​- Bundle Display Name will not be synchronized to the final generated package body Info.plist file. This indirectly leads to the problem that setting the Display Name in the Xcode panel does not take effect.

3. Solutions

The following discussion is the case of using the old Info.plist file generation mode (GENERATE_INFOPLIST_FILE=NO), and using the new Info.plist file generation mode theoretically will not have this problem.

Option 1 (recommended):

修改 Info.plist 文件中 CFBundleDisplayName(没有该字段则添加)的值为$(INFOPLIST_KEY_CFBundleDisplayName)

$(INFOPLIST_KEY_CFBundleDisplayName) is the environment variable corresponding to the value of Build Setting - Info.plist Values ​​- Bundle Display Name (as shown below).

Tips: How to get the environment variable name corresponding to the field in Build Settings?
Select a field, command+C to copy, find a text editor and paste it with command+V, you can see it

Option II:

直接在 Info.plist 文件中修改 CFBundleDisplayName(没有该字段则添加)的值为你App的名字

This solution can make the App name take effect, but the disadvantage is that the Xcode panel and Info.plist are out of sync . For example, if you change CFBundleDisplayName to "Wahaha" in Info.plist, the name of the App will become "Wahaha" after taking effect, but the old value "ABCDE" will appear in the Xcode panel.

Author: CocoaKier
Link: https://juejin.cn/post/7197361396219772983
Source: Rare Earth Nuggets
The copyright belongs to the author. For commercial reprint, please contact the author for authorization, for non-commercial reprint, please indicate the source.

Guess you like

Origin blog.csdn.net/txl910514/article/details/130380760