iphone: Use different icons with different build targets?
Right now I have a regular iphone app with unique springboard icon and splash screens. Now I want to create basically the same app with minor changes - and this app will have a different name, different springboard icon and different splash screens. So basically what I did now was to duplicate the original buil开发者_开发百科d target - but how do I add another icon.png to my project and tell XCode to use the relevant icon for each build? And what about the splash screens?
Xcode 6 – Xcode 9
- Go to images.xcassets and click the plus button to create a new app icon. You should have one app icon set for each build.
- Go to project -> build settings and search for "asset catalog app icon set name". In each of your targets, change the name of the app icon set name to match the names you entered in step 1.
Every target will have a different info.plist file
In this file you can specify icon, splash screens, displayed name ...
It is not necessary to drag your iconfiles to the helpareas on the summary of the target. Just name the files correctly (Icon.png, Icon@2x.png etc.) and add them as resources in your project and make sure to only add them to the bundle of the target they are needed in, and they will be used automagically.
You could create two sets of iconfiles, and when dragging them into your project uncheck the boxes for the targets they are not used in.
Ok I found the answer and it's rather simple. As I already mentioned I duplicated the target that I have - and changed the product name. Then there is the tricky part with the app icon and the splash screen. What I basically did was to delete these files from the project folder and move them to an external folder. Then I would create another external folder for images of the new target. Then I would add references of the images (very important not to copy them!) to the project for each build.
Hmm... every time I try to use the externally-referenced icon by dragging it onto the summary pane, a copy is also made to the root directory of my original project- the two icons are trying to live in the same place.
I had disabled the check mark to copy files if necessary, but it does it anyway (Xcode 4) making me think those files need to be in the root to work.
Am I missing something, should I be naming my files differently for the two versions, for example?
Details
Xcode 9.3.1
Solution
STEP 1. Prepare resource folder
In this folder we will prepare images for the application
My app root folder with Resources folder
- icon_Base_Production.png, icon_Base_Staging.png, icon_CI.png - icons for different targets
- icon.png - Current icon for generateIcons script. It is created automatically by generateIcons script.
- generateIcons - script which creates a set of icons for an application from one image
generateIcons code
nvm install 6
nvm use 6
#https://github.com/dwmkerr/app-icon
npm install -g app-icon
app-icon generate --icon "${0%/*}"/icon.png --platforms=ios
STEP 2. Add run script to your project
INFOPLIST_MYAPP="${SRCROOT}/SM2/Application/InfoPlist/Info.plist"
ICON_NAME=""
case "${CONFIGURATION}" in
"Debug_Staging" | "AdHoc_Staging" | "Test_Staging" | "Profile_Staging" )
ICON_NAME="icon_Base_Staging.png";;
"Debug_Production" | "AdHoc_Production" | "Distribution" | "Test_Production" | "Profile_Production" )
ICON_NAME="icon_Base_Production.png";;
"AdHoc_Production_SM2_CI" )
ICON_NAME="icon_CI.png";;
*)
;;
esac
cp -r "${SRCROOT}/Resources/${ICON_NAME}" "${SRCROOT}/Resources/icon.png"
${SRCROOT}/Resources/generateIcons
cp -rf ${SRCROOT}/Resources/AppIcon.appiconset/ ${SRCROOT}/SM2/Resources/Images.xcassets/AppIcon.appiconset/
All build schemes
Result
Each time you switch the build scheme, the necessary icons will be created.
Add the icons files only to the relevant target, then add them to you info.plist file under "Icon files" (must be done twice, there's another one for iOS5).
Usually it is done for you if you follow the file naming convention:
for iPhone:
- Icon.png
- Icon@2x.png
for iPad:
- Icon-72.png
- Icon-72@2x.png
精彩评论