iOS uses the same project to create two different versions of the app

Source: Internet
Author: User

Http://www.cocoachina.com/ios/20150916/13324.html

If the same app requires an ad lite version, a pro version with no ads. So the question is, how to achieve it gracefully?

There are generally two ways to implement this:

    1. A copy of the current project and then modify, this will lead to late maintenance costs too high, each modification should be changed at the same time two projects, to the late modification is almost frost, but the operation of the Fool type.

    2. The other is to create two target in a project, and then by judging the target to modify the code, which is based on the same set of code to make changes, only a few different places through the target to add various code, late modification maintenance cost is low, recommend this way.

    • Do not want to see the tutorial children's shoes, click here to download I have completed the good code.

Create a two target:

1. First select the target an already existing version, right-click Duplicate

2. Then select Duplicate only in the pop-up selection box

3. After creation your new target should be the same as mine, next we will modify target, Scheme, info-plist, so modify:

4. After the modified target, Scheme, plist name, you need to add the corresponding plist file in the new target, modify the Cfbundledisplayname to modify the name of the application.

5. Also remember to modify the product name or your bundle identifier suffix has copy and your target name is not the same, you also need to make a change in the bundle setting.

Start adding different AppIcon to two different applications, launchimage

In this option use images.xcassets inside set AppIcon and launchimage, note here one is AppIcon, the other is AppIcon-2, later when the target is compiled he will follow the settings here to get the boot diagram and icon

2. Into the Images.xcassets watch is not all check the two target, keep the same as I tick, if not checked, you can compile the different target will not get the resources.

3. Choose a different target to compile, your results should be the same as mine, with different appname and APPICON, there are different launchimage, but the code is shared, here you have succeeded half, Next you'll want to know how to differentiate the target in the code and add other features to it.

Use macro definitions in your code to differentiate between different traget

1. In the bundle setting set the Proprecessor macros add a kfree kpro parameters to distinguish the end is that traget. In the code for the need to use this macro to determine the code block.

2. Add proprecessor macros inside the code inside the macro definition, you will find that before compiling Xcode will intelligently choose different code. This allows you to share a project to manage two different versions of the application, with most of the code reused and maintenance management very easy.

Summarize:

Every year, Apple launches new technologies that are designed to reduce development costs and better design, and the development model as a developer should be consistent with Apple's philosophy. Use the most elegant and concise way to realize the function.

iOS uses the same project to create two different versions of the app

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.