LITE and easy

andrei (02/01/2012 - 21:23)

Amazingly enough, I was not able to find straightforward instructions on how to build both FULL and LITE versions of the same iOS app with XCode 4.x.  It did not took much time to figure out. Still, this blog post may save you some grief.

Goal

I wanted to build FULL and LITE versions of my app (MapPocket) from a single XCode project. I wanted to be able to use C Preprocessor (#ifdef/#ifndef) to control which parts of the source code are shared between FULL/LITE and which parts are specific for FULL or LITE.

Steps

1) Select your FULL project target and "Duplicate" it.

2) Assuming that your FULL version target was "myGreatApp", your new target will have a name like "myGreatApp copy".  You can rename it to something more suitable by clicking on the target name (in the same way as you renaming files in the Finder). This name has no significance and just lets you to distinguish one build target from another.

3) Select your newly created target and go to "Build Settings". Enter "Product Name" into search field.

You will see "myGreatApp copy" as a Product Name.  You can change it by double clicking on the value. Pay attention! This is what will be used to build "Identifier" for LITE version of your app, so something like "myGreatApp-lite" should work.

4) While still looking into "Build Settings", enter "Preprocessor Macros" into search field.

You will see "DEBUG" defined for "Debug" builds and nothing for "Release" builds.  Add something like "LITE_VERSION" to both "Debug" and "Release" (in the screenshot above, I have added "MP_LITE" symbol).

Now you should see something like this in your Schema selector:

Choose which version you want to work with (FULL or LITE) by selecting an appropriate Schema.

FAQ

1) How do I control which file belongs to which version?

Select any file. Open right pane. Select "File Inspector" tab (leftmost).

 

In "Target Membership" section you can choose to which target(s) the file belongs to.

2) How can I execute a portion of the code only in FULL version or only in LITE version?

This is where "Preprocessor Macros" are going to be useful. Assuming that we defined "LITE_VERSION" in step #4 above, following preprocessor directives could be used to make portions of the source code to be present in FULL or LITE version:

#ifdef LITE_VERSION
... This code will be present only in LITE version 
#endif  

#ifndef LITE_VERSION 
... This code will be present only in FULL version 
#endif  

#ifdef LITE_VERSION 
... LITE version 
#else 
... FULL version 
#endif

NOTE: You can read more about Preprocessor here

3) How can I remove a portion of UI in LITE version?

If the difference between FULL and LITE version of UI is huge, you probably would have to create a separate XIB for LITE version. However, quite often all you need to do is to remove access to some Premium feature. You can easily do it by using FAQ #2.

- (void) viewDidLoad {
  #ifdef LITE_VERSION
      self.myPremiumButton.hidden = YES;
  #endif	
  ... 
}

4) How can I make a button to do different things in LITE version?

Once again, FAQ #2 could be utilized.  If you need a button to do one thing in FULL version and a different thing in LITE version, all you have to do is to change an action associated with the button (assumption is that you will link FULL version of the action in XIB).


- (void) viewDidLoad {
#ifdef LITE_VERSION
  self.myPremiumButton.action = @selector( liteVersionOfPremiumAction: );
#endif	
  ... 
}

- (void) liteVersionOfPremiumAction: (id) sender {
  ...
}

5) How can I have different splash screens for FULL and LITE versions?

 First of all, do not try to do it "normal" way by dropping LITE version of splash screens into a right spot on XCode. This is what you should do:

- create a folder where you are going to keep splash screens for FULL version (lets call it "full" )

- move all splash screens images into this folder ( Default.png, Default-Portrait~ipad.png, ....   you can read here all about splash screens file names)

- add this folder to the project (via "Add files to ... ") and make sure that files from this folder are associated with FULL version only.

- create another folder where you are going to keep splash screens for LITE version (lets call it "lite" )

- copy LITE version of splash screens into this folder

- add this folder to the project and make sure that files from this folder are associated with LITE version only.

- select FULL version target, click  "Build Phases" and then look into "Copy Bundle Resources".  You should see a number of files marked with red color (one for each splash screen image). Select all red files and delete them.

Share and enjoy!

Add new comment