Set: Cannot Perform Set On Containers - ios

I am trying to update CFBundleName & CFBundleDisplayName in Info.plist using PlistBuddy
/usr/libexec/PlistBuddy -c "Set : CFBundleName test" info.plist
/usr/libexec/PlistBuddy -c "Set : CFBundleDisplayName test" info.plist
It works perfectly when the file is outside of the Xcode Project But when the file is inside the project It throws "Set: Cannot Perform Set On Containers"
Why it happens and how about solving this without moving the file outside of the project.

Space between colon(:) and key name is the reason why it was throwing the error and now it works as expected
/usr/libexec/PlistBuddy -c "Set :CFBundleName test" info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName test" info.plist

Related

Change bundle id and name depending on dart-define argument

The general goal is to have two copies of the application installed at the same time, but with different names.
One for the production environment, the other for the test environment.
The environment is NOT determined by the build type (release/debug/profile), but by the value of the -dart-define=myEnv="production/test" variable. And all builds making with --release mode in the ci/cd system and go on a Testflight.
If I understand correctly, this requires changing the App ID.
I have two info.plist files:
ios/Runner/Info.plist:
<key>CFBundleIdentifier</key>
<string>com.testcomp.testapp</string>
ios/Runner/GoogleService-Info.plist
<key>BUNDLE_ID</key>
<string>com.testcomp.testapp</string>
and also the application identifier is specified in the file:
ios/Runner.xcodeproj/project.pbxproj
as:
PRODUCT_BUNDLE_IDENTIFIER = com.testcomp.testapp;
How can I change the Bundle id and Bundle name of the application based on the --dart-define variable?
What I have tried:
Although this script is based on the release/debug parameter, I still tried to add this script to the Build phases:
if [ "${CONFIGURATION}" = "Debug" ]; then
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier com.testcomp.testapp.test" "$PROJECT_DIR/Runner/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleName testapp-beta" "$PROJECT_DIR/Runner/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName testapp-beta" "$PROJECT_DIR/Runner/Info.plist"
/usr/libexec/PlistBuddy -c "Set :BUNDLE_ID com.testcomp.testapp.test" "$PROJECT_DIR/Runner/GoogleService-Info.plist"
echo "Changed bundle id and name for Debug"
else
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier com.testcomp.testapp" "$PROJECT_DIR/Runner/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleName testapp" "$PROJECT_DIR/Runner/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName testapp" "$PROJECT_DIR/Runner/Info.plist"
/usr/libexec/PlistBuddy -c "Set :BUNDLE_ID com.testcomp.testapp" "$PROJECT_DIR/Runner/GoogleService-Info.plist"
echo "Changed bundle id and name for PRODUCTION"
fi
but the behaviour was strange:
the first attempt to build after a complete cleanup occurs without error. But the installed application has the old ID and name. The second attempt to build installs the second app with a changed ID and name and a second shortcut appears on the device, but then the Xcode crashes with the following message:
I think that this is due to the fact that the script is editing info.plist files, but flutter store the identifier directly into the ios/Runner.xcodeproj/project.pbxproj file, and I could not change it with the script.
I also moved this script to the very top of the Build phases, and also moved it to the Product->Scheme->Edit Scheme...->Build->Pre-actions. This did not resolve the error.
But again, I need to change Bundle ID and name not depending on the build mode (--release or debug), but from the value of a dart-define variable.
Flutter version: 1.22

How to enable 3D touch(static quick actions) only in debug mode?

Our team is developing an app, and I'd like to add some home screen quick actions just for debug purposes. Also, I want it to be enabled immediately after a fresh install, which means dynamic quick actions would not be an option. However, I have no idea if we can enable static quick actions only in debug mode. Is there any way to achieve this?
You have two major options for this:
- The GENERAL option for any kind of file:
The cleanest way is to have separate files for each configuration. Then:
You can set the path for each configuration in project build settings like this:
Or you can use run script for this or any file you need to change during the build process:
Create two different info.plist files, one for the debug and another for production
Head to the project build settings and create new run script phase
Use the following script:
sourceFilePath="$PROJECT_DIR/$PROJECT_NAME/"
debugFileName="Debug-Info.plist"
releaseFileName="Release-Info.plist"
if [ "$CONFIGURATION" == "Debug" ]; then
cp $sourceFilePath/$debugFileName "$INFOPLIST_FILE"
else
cp $sourceFilePath/$releaseFileName "$INFOPLIST_FILE"
fi
Note that in this example:
I use Debug-Info.plist for debug mode file.
I use Release-Info.plist for release mode file.
I copied all files in same directory as the original info.plist file.
But I made all variables and you can change them to whatever you want.
- The More SPECIFIC option for any plist file:
Since Info.plist is a property list, you can use PlistBuddy to edit any value of of it directly. Here is the example script to add a shortcut item if it is in debug mode only:
/usr/libexec/PlistBuddy -c "Delete :UIApplicationShortcutItems" "$INFOPLIST_FILE"
if [ "$CONFIGURATION" != "Debug" ]; then
exit
fi
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems array" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "delete :UIApplicationShortcutItems" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems array" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems:0 dict" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems:0:UIApplicationShortcutItemIconType string UIApplicationShortcutIconTypePlay" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems:0:UIApplicationShortcutItemTitle string Play" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems:0:UIApplicationShortcutItemSubtitle string Start playback" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems:0:UIApplicationShortcutItemType string PlayMusic" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems:0:UIApplicationShortcutItemUserInfo dict" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems:0:UIApplicationShortcutItemUserInfo:firstShortcutKey1 string firstShortcutKeyValue1" "$INFOPLIST_FILE"
Remember to run this script sometime before Copy Bundle Resources.
I recommend you to always put script codes inside a separate file and call just call it in the build phase.
Obviously the problem is that you are asking an entry in the Info.plist to be present for the debug configuration but not for the release configuration. The contents of the Info.plist don't come and go automatically depending on the configuration. But what file is used as the Info.plist is something that can change depending on the configuration, because it's just a build setting. So one way to solve this would be a special configuration and a special Info.plist to go with it.

How can I get the "Archive Name" (in Edit Scheme/Archive/Archive Name) dynamically with the CFBundleShortVersionString in suffix?

With the same way that ( $(PRODUCT_NAME), $(EXECUTABLE_NAME), $(PRODUCT_BUNDLE_IDENTIFIER) ), is it possible to get the executable name of the file (in the Info.plist) with the version number (for example $VERSION or something like this) ?
For now, I have $(TARGET_NAME), I would like to add the version number (CFBundleShortVersionString). example : Name_of_the_App_v1.45.ipa
Changing the "product name" like in the following picture doesn't work :
For info, I use that script to increment automatically the build and the version in "Build Phases/Run Script".
#!/bin/bash
rm -rf build
Build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
Build=$(($Build + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $Build" "$INFOPLIST_FILE"
Version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INFOPLIST_FILE")
Version=$(echo "scale=2; $Version + 0.01" | bc)
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $Version" "$INFOPLIST_FILE"
The only thing that change the name of the ipa archive is in the section "Edit Scheme/Archive/Archive name" that takes by default the name of the Scheme. So You have to change the Archive name or directly change the value of the Scheme if you want to see that value in the name ipa.
How can I modify dynamically that Archive name, to add the CFBundleShortVersionString in suffix directly in the Run Script section or anywhere else
?
Thanks in advance.
This is possible by adding a User-Defined Build-Setting to your Target. Click Project -> Targetname -> Build-Settings -> Plus-Button -> Name: APP_VERSION, Value: 1.0.0. The newly defined build-setting is then available as preprocessor-variable $(APP_VERSION) in your Info.plist.
For clarity, you should also set your CFBundleShortVersionString to that variable, so the two Info.plist-Entries will always contain the same version-string.

Reading plist file from iOS project bundle

I have a plist file customversion.plist which contains 2 properties max_ver (string) and min_ver (string) and are assigned the values 0 and 10 respectively.
Whenever XCode prepares the build, I want to read min_ver value and override Info.plist version using shell script.
I have written the following script:
CUSTOMVERPLIST = "customversion"
buildNumber=$(/usr/libexec/PlistBuddy -c "Print MAX_VER"
${BUILD_ROOT}/${CUSTOMVERPLIST.plist})
buildPlist=${INFOPLIST_FILE}
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $CONFIGURATION-$buildNumber" $buildPlist
My problem is that it seems that customversion.plist file is not being read and not getting the value of min_ver.
Can someone please suggest me about how to read the plist file from project bundle?
Thanks in advance.
${CUSTOMVERPLIST.plist} is not a valid statement. This worked for me:
CUSTOMVERPLIST="${PROJECT_DIR}/${PROJECT_NAME}/customversion.plist"
buildNumber=$(/usr/libexec/PlistBuddy -c "Print MAX_VER" ${CUSTOMVERPLIST})
buildPlist="${INFOPLIST_FILE}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $CONFIGURATION-$buildNumber" $buildPlist

Setting UIPrerenderedIcon from a configuration file in Xcode

It seems I am not able to set UIPrerenderedIcon in my Info.plist, because it is ignored as of iPhone OS 2.1. You can't provide a String value of YES, this is no longer supported.
Is there any other way to do this without necessarly creating a separate Info.plist (e.g., using a preā€“build run script)?
I figured this out. You will have to add a "Run Script" build phase, before "Compile Sources":
#!/usr/bin/env sh
set -o errexit set -o nounset
/usr/libexec/PlistBuddy -c "Set UIPrerenderedIcon ${YOUR_CONFIG_KEY}"
"${PROJECT_DIR}/*-Info.plist"
If you want to set value dynamically using command from shell script or terminal, you can do that as below:
/usr/libexec/PlistBuddy -c "Set :UIPrerenderedIcon YES" YOUR_PLIST_FILE_PATH
/usr/libexec/PlistBuddy -c "Set :CFBundleIcons:CFBundlePrimaryIcon:UIPrerenderedIcon YES" YOUR_PLIST_FILE_PATH

Resources