info.plist for different target version - ios

One of my project needs to provide lite/full version and english/french version.
I know that localise and set info.plist/InfoPlist.strings for different luanguange.
But if I also hope to set the info.plist for different target version(lite/full).
How can I do?

When you create a new target Xcode will make a copy of the info.plist for the new target. In the target build settings you can even change the name of the info.plist used for that target.
The default name of the info.plist is something like copy-info.plist when you rename the file on the file system make sure that you also rename it in the build settings. The build setting key you need to change is Info.plist File.

Related

Access one targets Plist from Another target

I am currently trying to unify my targets inside of my application.
I have one codebase I build multiple versions of the app, all tailored to a different client using targets.
That said, I want to unify the build number and versions so when I write code and archive, all the apps are built with the same version/build numbers.
Can I have all the target plist files reference the main target plist for these numbers, so I do not have to go into each target and increment them?
Or should I have my appDelegate update its own target when archiving?
From what I understand you have multiple targets under the same project, and you want all the app's that the targets build to have the same version (that you set in one place). It is not so easy to read them from one info.plist, but it is easy to have one build setting variable that all the info.plist use.
Simply go to the info.plist for each of the targets and replace the value of the version with a variable value e.g. ${APP_VERSION}:
The go to the project's build settings and add a user defined value with that name:
and give it the value of the version you want:
Now the info.plist will have the version you set in one place(the APP_VERSION build setting), you can do the same for the other info.plist files so that all read the same value.

How to localize app name for with different build configurations?

I have a project that have 3 build configurations: Debug, Beta and Release. These configurations have different app name each. I am doing this using a variable like APP_DISPLAY_NAME and using it in Info.plist file.
I need to localize these app names.
Using InfoPlist.strings file with "CFBundleDisplayName", overrides these configuration names.
So how can I do this?
I have checked this and a couple more questions but still no result.
Here's how you can have different InfoPlist.strings for different build configurations in the same target.
In your Build Settings:
Specify a different Info.plist File (INFOPLIST_FILE) for each configuration.
Set Adjust Strings File Names for Info.plist (STRINGS_FILE_INFOPLIST_RENAME) to Yes. On Xcode 14, it was set to Yes by default.
Create .strings files with the base name of your Info.plist filename + Plist.strings.
For example, if your Info.plist filename is Beta-Info.plist, your strings file should have the name Beta-InfoPlist.strings. Make sure you include all of these strings file to your build.
Do not include an InfoPlist.strings file in your target.
The key to making this work is Adjust Strings File Names for Info.plist in the Build Settings Reference.
Adjust Strings File Names for Info.plist.
Setting name: STRINGS_FILE_INFOPLIST_RENAME
If enabled, renames .strings files whose basename matches that of the target’s Info.plist file, to InfoPlist.strings in the built product.
Example
Here's an example in my app which has 3 different variants (AdSupported, AdSupported-Dev, Pro) that require different app names.
Build settings. (I have debug & release configurations for each variant, but you could also do this with just Debug / Beta / Release.)
Strings files. They are all included in my target.
Info plist files. As usual, they are specified in the Build Settings and NOT included in my target.

iOS:I config my info.plist it did not work for my app,but I config the Target Info, it work for me

I config my info.plist it did not work for my app,but I config the Target -> Info, it work for me.
I have two target in my project,is this reason? If is this reason, how can I open the Target -> Info as code?
When you create a new target, Xcode automatically creates a separate -Info.plist file for it. Either edit the new file or update the -Info.plist path at the packaging settings to share the same file among different targets.

Wrong info.plist?

I need to make a free variant of my project's target. I duplicated the target, gave it a unique name, and changed all occurrences of the old name to the new name in the new target. I've made sure to enter the correct name for the info.plist file under the new target's Build Settings in the Packaging section.
But when I edit the new target's schema and click the Build options, both the new target and the original one appear in the list of targets. I cannot uncheck the Test and Run boxes for the old target (which the Apple docs mention but do not explain).
My problem is that when I examine the info-plist settings for the new target at runtime (using NSBundle objectForInfoDictionaryKey) I see values from the original target, including the Bundle Name and Bundle Identifier. I would like the new target to use it's own info.plist only, and ignore the original info.plist.
What am I doing wrong?
I fixed this by going into Manage Schemas, deleting the schema that had been created for the new target, and then clicking Autocreate Schemas Now. This created one new schema for the new target and it contained only one target. At runtime, the new target now shows values from the new info.plist.

Info.plist and its variables like ${APPNAME}

I am preparing Info.plist for my iOS application. I want to carefully set each option. However, there are some weird variables like ${REGION}, ${APPNAME}, ${EXTRA_ICONS}, etc. I guess they are set via Xcode?
I don't want Xcode to mess with the values. Can I simply set them? For example, for ${REGION} insert "en". For CFBundleDisplayName – nothing, because the docs says:
If you do not intend to localize your bundle, do not include this key
in your Info.plist file. Inclusion of this key does not affect the
display of the bundle name but does incur a performance penalty to
search for localized versions of this key.
And so on. Can I simply do this? What to insert for "CFBundleExecutable"? I guess I have to know what Xcode generates?
This is horrible design, as there are two sources of values: the plist itself, and some stupid meta-plist inside Xcode.
Your Info.plist file is processed by Xcode thanks to the "Expand Build Settings in Info.plist Files" (INFOPLIST_EXPAND_BUILD_SETTINGS) Build Setting of your Project.
That's usually a great feature, as it avoids to have a different Info.plist depending on your build settings and configuration, and avoids you to modify the settings in multiple places. But if you really don't want it, simply turn this settings off in the Build Settings of your project or target.
I suggest you keep this setting on anyway, so that the values chosen in your build settings will be reported in your Info.plist, and if you need to change stuffs like the application name for example, change it in the Build Settings directly. This way you will keep consistency between your build settings and your Info.plist file, instead of risking to have an inconsistent configuration.
A great example is the one you wrote yourself in your own question : the CFBundleExecutable entry of the Info.plist file. This entry typically have to contain the name of the executable in your bundle (so that iOS knows which executable to launch inside your .ipa bundle).
This value typically depends on your Build Settings, typically the EXECUTABLE_NAME build setting. If you ever change the name of the generated executable (in the Build Settings of your project or target) and you did put some constant string for this value in the Info.plist, you obviously need to change this CFBundleExecutable key to the new name of the executable generated by Xcode. If you use ${EXECUTABLE_NAME} as the value for this key (and kept the processing of your Info.plist turned on in the project settings), Xcode will replace it for you, ensuring that the Info.plist is consistent with your Build Settings and with the name of the executable it has generated.
I don't see any advantage of disabling this processing phase of the Info.plist file by Xcode ; you should take advantage of it and keep using the ${xxx} build variables so they are replaced by their real values Xcode dynamically at compile time thus ensuring consistency and avoiding errors.

Resources