开发者

Adding a target to an Xcode project

开发者 https://www.devze.com 2023-04-05 04:15 出处:网络
I开发者_StackOverflow社区 have an iPhone application which is currently in the app store.I want to make what is effectively exactly the same application, but which is free of charge and features ads.

I开发者_StackOverflow社区 have an iPhone application which is currently in the app store. I want to make what is effectively exactly the same application, but which is free of charge and features ads.

My plan was to effectively just copy the project, create a new one and add ads into the code and release as separate app. However, someone mentioned that the best solution would be to add an additional target to the existing application, providing two binaries at run time.

Seems like a good solution to me, however I am a little confused as to how I would go about altering the code to have ads built into the new target, and leaving the original untouched?


I followed this tutorial which, although old, was basically the same for xcode 4. I duplicated the target and p-list, making sure I was able to run it with changes and not affect the full version target.

I then duplicated the .xib files that would be different. If you look under the project settings, somewhere you can find a list which allows you to choose which resources are included. Include the lite version's xibs in the the lite version, and the full version's in the full respectively. Then you will be able to edit each without affecting the other.

The icons and images can be changed in the same way. Simply create a lite version icon set or other set of images and include the lite icons in the lite target's resource settings instead of the full version's images.

Also, you'll want to create some preprocessor macros. In the build tab look for them, and crete a macro called LITE_VERSION (or whatever you want, it doesn't really matter) for every preprocessing option - debug, distribution and release.

That allows you to add differing code in the same .h and .m files. Simply use

#ifdef LITE_VERSION
// Lite version only code here
#endif

to separate the two. You can also use #ifndef LITE_VERSION to add code only to the full version.

That's it! After all of the above steps, you should be able to edit the lite version's .xib files, put code into the lite or full version only, and have separate images and icons for each.


XenElement's answer is correct. But you should see the best practice to do it. You should have an identifier class to check for targets. If you use macros everywhere in the code, it won't seem good for you and other developers as well. In this little blog post you can see how to create that kind of an identifier class and learn some best practices about targets in xcode.


I followed this Just2us: How to create multiple targets for Xcode iPhone Projects tutorial.

I decided change step-3 with Stu's clue, setting FULL_VERSION explicitly in the paid version.

"To address the concern of not having accidentally LITE_VERSION defined as a macro preprocessor (thus releasing a full version accidentally), I put this little snippet of code in a header file (it just needs to be somewhere in the code base , just make sure that is common to all configurations)":

#ifndef LITE_VERSION
    #ifndef FULL_VERSION
        #error You probably forgot to specify if this is the Lite or Full version of the app
    #endif
#endif

PS: I wrote the code above right after the #import in AppDelegate.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号