Kiddo
Kiddo

Reputation: 5082

images path for icons and launch images in info plist

i would like to add several different resources folders contains different app icons into one project.

then set up 5 different apps in the project targets. I have created different info.plist for each one. how can i specify different icon files and launch image files for each app?

I would have 5 different folders contain icons images e.g app1/icon.png app2/icon.png

I have tried to add the path into the plist, but seems it can't pick up the files.

if I tried to add icon files in the Targets-Summary tab, it just copies them into the root folder and overwrites the previous ones.

I can do a quick fix by adding prefix into images, e.g app1_icon.png, app2_icon.png

I'm sure there is a better way to do that.

Upvotes: 4

Views: 2595

Answers (2)

David Manpearl
David Manpearl

Reputation: 12676

How to Add Separate Icon and Other Files to Multiple iOS TARGET Applications in a Single Xcode PROJECT


So, you have multiple iOS apps that share a common code base in Xcode. You might be creating Lite/Pro, Free/Paid, or uniquely skinned versions of similar apps. You've already figured out how to duplicate the TARGETS and you've hopefully figured how to specify separate .plist files for each of them. You also realized how to use compiler directives (i.e. #define MACROS) specified in "Build Settings" > "Preprocessor Macros" to enable and disable slightly different behavior in the various Target apps.

Now you are trying to specify the icon files for each target and running into difficulty. You will have the same problems if you attempt to use different "Default*" launch images or other resources in which you want each of the Targets to use different graphic resource files with the same set of file names.

Here is what you have to do:

  1. Make a directory for each of your targets such as 'App-A' and 'App-B' into which you may place the identically named sets of files consisting of icons and whatever else.

  2. Make Xcode Groups in the project hierarchy with the same names as the various Target directory names. This is not required, but makes life easier for me as you will see in Step #9.

  3. Add your icons and other images to these groups. Yes, they can (and should) have the same name from Target to Target. For example, you can have "icon-57.png" in both App-A and App-B.
    Hint: Before adding files to each Group, set Xcode to build for the Target associated with that group. For example, if you are going to add an image to App-B, in the upper-left of the Xcode interface near the 'Run' and 'Stop' buttons, select "App-B > My iPhone" in the options menu. This will associate your image membership with the correct Target and help you in the next steps. This Hint is not required.

  4. Now for the important part as suggested in a comment above by @rckoenes. You must set the target membership for each of the files you added. Click on each Target, select "Build Phases", and spin down "Copy Bundle Resources". You must add the images appropriate for that Target and delete images used by the other Target or Targets. If you followed the 'Hint' in the previous step, this may already be setup correctly for you. Nevertheless, in the following steps this list will probably get damaged, and you will have to come back here and adjust it again.

  5. You are now finished for general resource images that get used throughout your apps. You may have used this method for an image or button graphic in your project that needs to look different in each Target. It shall now be so.

  6. Icons and Default* background images are a different story because of the Target Summary panel that allows you to populate these resources with drag-and-drop. The next steps will help you with that.

  7. For each of your targets, drag icon and launch image files to the image holders in the Summary screen. Of course, they must be the correct size. Xcode will ask your permission to copy those files to the root directory of your project. Allow it, you'll be deleting them later. During subsequent passes, Xcode will ask permission to overwrite the files already in your root directory. Again, allow it.

  8. In Xcode, delete all of the newly copied icon and launcher image files that have appeared in the root of your project. Allow Xcode to move them to the trash.

  9. Finally, all that creating, moving, and copying of files may have wreaked havoc with your Target Memberships. Return to the instructions above in Step #4 and clean up all your memberships. You can easily spot images included in one Target from those of a wrong Target because the path is displayed following the filename. This is just one of the reasons we should be careful to create directories and Groups with the matching Target names as recommended in Steps #1 and #2.

Each of your apps will now display the correct application icon and launcher background image.

If your app was previously installed with no application icon or the wrong icon, you may have to delete the app and reinstall it in order to see the new icon.


The following picture can aid in the visualization of multiple Targets:
Targets

Upvotes: 2

rckoenes
rckoenes

Reputation: 69499

By including the the images per target.

So app1 include the app1/icon.png but not any other and app2 includes app2/icon.png.

Upvotes: 0

Related Questions