---
title: "Free and Pro versions"
slug: free-and-pro-versions
section: tech
date: 2014-05-27T19:12:00.000Z
canonical: https://roland.leth.ro/blog/tech/free-and-pro-versions
---

For my first 2 games I had a project for the Pro version and another project for the Free version, and, as everyone knows, that's a huge pain to maintain. 

So, at first I created this:

```objc
#define kFreeVersion ([[[NSBundle mainBundle] infoDictionary]\
[@"CFBundleIdentifier"] isEqualToString:@"com.rolandleth.appnamefree"])
```

and added a warning in the App Delegate:

```objc
#warning Reminder: Don't forget to check this on every release!
if (kFreeVersion) {
    // do stuff for the free version
}
```

But this implied, as the `#warning` suggests, to never forget about manually changing the bundle ID at every release. So searching I went and I found [this](http://stackoverflow.com/questions/7975729/two-versions-of-ios-app-free-and-paid-how-to-conditionally-change-project-id), then [this](http://www.bit-101.com/blog/?p=2098). 

Pretty basic stuff, which I never thought about. I combined the 2 approaches, and now I have 2 targets, but use the above macro instead because I think `#ifdef`s make the code look ugly.

Combined with this script (I have *Run script only when installing* checked):

```bash
VERSIONNUM=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INFOPLIST_FILE")
NEWSUBVERSION2=`echo $VERSIONNUM | awk -F "." '{print $2}'`
NEWSUBVERSION3=`echo $VERSIONNUM | awk -F "." '{print $3}'`
NEWSUBVERSION3=$(($NEWSUBVERSION3 + 1))
NEWVERSIONSTRING=`echo $VERSIONNUM | awk -F "." '{print $1 ".'$NEWSUBVERSION2'" ".'$NEWSUBVERSION3'" }'`
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $NEWVERSIONSTRING" "$INFOPLIST_FILE"
```

makes releasing 2 versions of an app much easier than what I was used to.

*Edit, 10 minutes later*: Well, I had to switch to the `#ifdef` approach, because I wanted to remove all the ad related frameworks from the paid version, so I don't have any troubles with the approval. Oh well...