See Android Free and Non-Free Builds also.
Software Versions
- XCode 4.5.1
Create Project
The odds are you already have a project you are planning on turning a free and non-free version. It is probably safer to start with a new project to figure out any of the details before jumping in with an existing current project. Though if you want to just jump in with your current project skip this step.Duplicate Target
Select the target and use Command^D to duplicate the target. This will create a second target with the original name and append copy. The next couple steps change the name of that target to the free version.Rename Target to Free
Double click the target name and change it from 'copy' to 'Free'.Rename Product to Free
Select the Build Settings for the new free target. In the Packaging subcategory set the Product Name to free name.Rename Target 'copy Info.plist'
When the copy of the new target was created it made a new Info.plist file for the target. Rename this to the name of your target.Move Info.plist Into Project Directory
For whatever reason the duplication process drops the Info.plist file in the root directory of the workspace rather than the project. Maybe different versions of XCode will fix this issue. So click on the Info.plist file and Show in Finder.Move the file into the project's directory, not the .xcodeproj directory.
Delete Old Info.plist Project Reference
Since the Info.plist file has been moved and XCode isn't smart enough to realize that it was moved we need to delete the old reference.Add Info.plist to Project
Re-add the Info.plist to the project. In the Add to targets clear the original target and check the new project for add to targets.Move to Supporting Files
Drag the Info.plist file to the Supporting Files next to the original target's Info.plist. This part isn't absolutely necessary, but we might as well make it look nice.Select Info.plist for Target
The last step for hooking up the Info.plist is to set it for the target.Add C_FLAGS
This step adds the dash of magic which allows use to distinguish between versions. The -DVERSION_FREE will allow use to use #ifdef within the code to enable and disable blocks of code depending on the version. It is possible to add additional defined versions to each of the build, for example if you were doing an application for each baseball team.Update View Controller
To show an example of using #ifdef create a UILabel in the view controller and set the text to a different value for each of the targets. The free version would display "iExample Free" and the non-free version would display "iExample".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "ViewController.h" | |
@interface ViewController () | |
@property IBOutlet UILabel* greeting; | |
@end | |
@implementation ViewController | |
@synthesize greeting; | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
#ifdef VERSION_FREE | |
self.greeting.text = @"iExample Free"; | |
#else | |
self.greeting.text = @"iExample"; | |
#endif | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
@end |
No comments:
Post a Comment