Add multiple targets for version control in Xcode when developing iOS

Source: Internet
Author: User

In iOS development, we often encounter the development of multiple versions of the same app (Pro, Lite, free), and here's the question of Xcode adding multiple targets to version control, here's a quick explanation:

Click on the project name on the left, project and targets will appear on the right, click on your target now, if called a, right-click Pop-Up menu, select Duplicate, copy the same target, copy target is generally called a copy,a Copy and A's settings (compile conditions, source files, resource files) are exactly the same, you can modify a copy of the compilation conditions and resource files as needed;

1, a copy of the name is not professional? Now let's change it:

1) First modify the target name in the upper-left corner of Xcode:

Click on the top left corner of the Xcode run, stop to the right of the project name, drop-down box select Manage schemes, in the pop-up box, click a copy that line, click once, then click once, you can modify a copy for the name you want, such as alite;

2) Modify the name of a Copy.app under the products in the lower left of Xcode:

Click Targets under the alite you just renamed, click Bulid Setting, search packaging under the private Headers Folder Path, modify a copy.app/ Privateheaders is: alite.app/privateheaders;

2, change the bundle identifier and choose different certificate, let the app distinguish

1) New target needs the. plist file

Create a new folder X, add X to the project, choose Target as alite when adding, do not select Target A, because it is not shared Copy the original target's a-info.plist to X, modify its name to Alite-info.plist,xcode in the right-click Add File to ..., select Add to target alite;

2) Click Target:alite->summary: Prompt You need to select Plist file, select 1) to add the alite-info.plist;

3) Click Target:alite->summary: Set bundle idenfitier;

4) Click Target:alite->build settings->code Signing: Select another certificate;

3. Modify the program name

In general, multiple target program names are different, copy zh-hans.lproj and en.lproj under the Infoplist.strings file to the X,xcode right-click Add File to ..., select to be added to target alite And then modify the contents of Infoplist.strings: Cfbundledisplayname= "program name Lite";

4, 2 target to create now, when you add a resource file, you control the content of different versions by selecting the target you added; What to do with precompiled macros: Target->build Setting, search: Preprocessor Macros, set the debug and release in the precompiled macro content, such as target_version_lite=1 for LITE version (note = front and back can not right space, there are spaces will compile but), the program in different versions of the judgment:

#if Target_version_lite ==1

...

#elif Target_version_lite ==2

...

#endif

Reference article:

1, http://blog.163.com/lengfeng_04/blog/static/80470603201273111549529/

XCode creates multiple target from the same project

Due to project requirements, the same project needs to send two versions, two versions only a small number of different, specifically to study the target, small to understand, the creation of the target record, easy to view later, if there is an omission, please correct the netizen.

There are two ways of creating a target,

1 is created by creating a new target through file-->new-->target, then selecting one of the templates, the app type target, you can choose the empty application template, However, the new target has its own appdelegate and main, which has not been studied, how to reuse with the original appdelegate and main

2. Another method is to make a copy of the original target by duplicate it, and at present only studies how to create a new target by duplicate to make a record.

Assuming the original target name is a, we need to create a new target B

1. Right-click on the original target and select Duplicate,xcode to copy a target object named a copy and generate a scheme for a copy-info.plist and a copy.

2. Renaming

A) Renaming a copy target, you can change it directly by clicking Target and changing it to B

b) A copy-info.plist, by default generated in the program environment root directory, that is, a.xcodeproj sibling directory, if you want to put in the layer (for example, with A-info.plist in the sibling directory), you can first delete a in Xcode Copy-info.plist the index, then copy the file into the development directory, and then rename it to B-info.plist, in Add to project. In project build settings, modify the directory (relative path) of the Info.plist file option to B-info.plist, This will allow you to see the info page (that is, b-info.plist), and then modify the ProductName and bundle identifier to become another app. Prefix header path, depending on the specific needs and whether to modify, if the two target can be common with the same Prefix Header, then there is no need to modify the path here

c) modify scheme, in the debugging of the Stop button side, we can select all the target in this project to do the compilation, if not modified, the name chosen here is a copy, in order to unify with the new target, the same should be modified here name. Click the scheme selector, then choose Manager Scheme, find a copy and change to the name you want, such as B

The advantage of using duplicate is that if the two target has a lot of the same point, with duplicate, you can copy all the relevant settings, without having to make too many changes.

To generate a new target, it must be different from the original target, where you can define a precompiled macro to differentiate between two versions of different code, precompiled macros can be preprocessor macros defined in build settings, such as in our new target b Define the precompiled macro macros and then in the code by

#if defined (MACRO)

The code that the target B needs to execute

#else

The code that target a needs to execute

#endif

to differentiate

Other: Build phases (the content that each target compiles contains, it is important to note that if you create a target B and then add a resource or file to a, target B does not automatically increase these resources, you need to add them manually)

1.Compile Sources

code files that need to be compiled

2.Link Binary with Libraries

Libraries on which the compilation depends

3.Copy Bundle Resources

Compile the required resources

Each target can increase or decrease the contents according to the specific needs.

2, Http://kan.weibo.com/con/3550176548481250?_from=text

Http://stackoverflow.com/questions/1807377/xcode-multiple-targets-multiple-internationalized-names

Multiple target of the same code, the method of setting its name separately in support of multiple languages

It's not good to generalize this thing with a headline. Xcode 4.2+ introduces a file called Infoplist.strings in the project MultiLanguage Pack xx.lproj, which displays different display Name in different system languages for the same App. Like what:

Infoplist.strings (中文版)-

"Cfbundledisplayname" = "中文版 Name";
Infoplist.strings (Chinese)-"cfbundledisplayname" = "Chinese";

It's easy to do under single target, and you need to do a little extra processing when you target more. Create a new folder with the same name as the target under the project directory (with the same name for ease of differentiation), and then copy the Xx.lproj folder below the target, and the directory structure will look like this:

./target1/
En.lproj/infoplist.strings
Zh-hans.lproj/infoplist.strings
./target2/
En.lproj/infoplist.strings
Zh-hans.lproj/infoplist.strings

After copying keep the project directory under the Xx.lproj folder, which retains the localizable.strings, because the multi-language is generally universal, there is no need for each target long language. After copying the target1/xx.lproj only infoplist.strings. Then add to the Xcode project, open xcode-views-utilities (command+option+0), under target membership for different target to the corresponding folder under the Infoplist.strin GS corresponds to connected, done.

Original address: http://blog.csdn.net/ysysbaobei/article/details/10951991

Add multiple targets for version control in Xcode when developing iOS

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.