Michael Kaye asked me “how he can he handle things like Localizable.strings and InfoPlist.strings. You can’t have two copies of these files and there is no info.plist setting I can use to target the correct file with a different name. Plus how would one handle different Default.png for each target?” Answer to this question is very simple, you have to write a script which should run before compiling your application.
So in this tutorial I am going to write a Script file which will run before compiling and that script will overrite existing files and only copies required files for that build. If you didnt read first part of this tutorial, then I recommend you to read the first part before you continue reading this tutorial (Same Xcode Project Create Multiple Products for iPhone).
So in this tutorial I am going to handle different Default.png file for both lite and full versions, also I add different background screens for different versions. Out put will look like this
Take the old code which I used in first tutorial (you can grab old code from here). Open it in Xcode and drag two images files in to Xcode (just like we add images to the project), one is Default.png and other one is PakistanFlag.png (In my case both Image are same). Also place images folder anywhere you like, I place it inside my project (Note: please do not drag it in Xcode project)
Open your HelloWorldViewController.xib file and place UIImageView component (320×480 px) and provide “PakistanFlag.png” file as image. Map it to your HelloWorldViewController.h file.
Once we set-up everything for Xcode now its time to write a script for it. As we have two targets files inside Xcode project we have to do these steps for every target (Best solution would be you add a script to one target and then duplicate it). Please follow the following steps to write a script:
- In your project “Group & Files” panel expand “Targets” and right click on “HelloWorld” and select > Add > New Build Phase > New Run Script Build Phase.
- In Script TextArea write script file name with path of the script as well, which in my case is “./runtimeScript”
- Close this window and expand the target “HelloWorld” you will see a “Run Script” folder at the end. Move it to top in hiracry so that it runs before anything else compile.
- Please repeat step 1,2,3 for “HelloWorldLite” target as well. We will be using same script file for both tragets.
- Now its time to write a script for your project. Right click on “Resource” and select >Add > New File. Select “Other” from the panel and then select “Shell Script”. Click Next and give it a name you write in step two (runtimeScript) and do not select any target because we do not want to copy this file in our binary project.
- Open the script file and copy the below code inside of it
#!/bin/tcsh -f echo .runtimeScript: $TARGET_NAME if ($TARGET_NAME == "HelloWorldLite") then cp Images/PakistanFlag-Lite.png PakistanFlag.png cp Images/PakistanFlag-Lite.png Default.png endif if ($TARGET_NAME == "HelloWorld") then cp Images/PakistanFlag-Full.png PakistanFlag.png cp Images/PakistanFlag-Full.png Default.png endif #
Now its all setup. Select different version and see the result. I hope this help you Michael Kaye. You can grab the code from here.
Popularity: 8% [?]