iOS development-a project for multiple environment switching, suitable for people who need to play a lot of different environmental packages often

Source: Internet
Author: User

The following configuration is not valid under the SWIFT project with a small partner, so the blogger has identified a slight difference between swift configuration and OC after a study, and if you are the SWIFT project, please go to the SWIFT version: Click here to
do not know if you need to pack regularly. All kinds of bags, test clothes, formal clothing, development clothing and so on, each need to note open a different domain name, sometimes inadvertently forget that there may be no small loss, how to regulate these environments. Bloggers today teach you how to separate the different environment, only to select the corresponding target can switch different environments:
1. We first build an empty project, the name is hello;

2. After creating a good project, select our target, right-click:

3. We assume that the formal environment, the development environment, and the test environment, the original target is the formal environment, so we need to create an additional two target, continuous operation two times after:

4. After this step, it is created, and then renamed:

5. After changing the name, the left corresponding plist file name also changed, and then back to target, because plist name changed, so can't find, click Choese .... button, select the corresponding plist file.
When you're done, because you have three target, it's inconvenient to check it out multiple times:

6. So here to create a Lib file, the overall management:

7. Click to the bottom:

8. Click Next to enter the name, Call Hellolib, then select target:

9. Add the newly created Lib to

10. At this point you will find that the target name in schemes does not correspond:

11. Remove all items Here, click "-". Delete finished, then point "+" came out, deleted a few times to add a few oh.

12. Close after completion, and then create new files Remember to check the Lib file, do not check target again, but the appdelegate file does not move, because this is the origin, of course, if you check lib, do not check target also can be, there is no impact
Note here, only m files can be checked, h file can not oh.


13. Here is not finished, different environments we have created, but select the corresponding target after the corresponding different domain name we have not configured, in the build setting input preprocessing:

14. See the red box circled the one, because the current selected is the official target, so there is no need to fill, the default is Debug=1, do not touch, and then select Dev and text, respectively, add dev=1,test=1, name casually write, the following will be used,

15. After the operation, into the appdelegate, in the method:

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions{
#ifdef DEBUG
    url = @ "http://bbbbbbbbbbbbbbb";

#elif DEV
    url = @ "HTTP://CCCCCCCCCCCCCC";

#elif TEST
    url = @ "http://dddddddddddddd";

#endif
//Whether it is set up rootviewcontroller or through the storyboard can Oh,

}


16. You can switch target in the schemes, under which target, which is the definition of the URL is color (switch the target when you need to switch back and forth file to see the corresponding URL color change, or before the URL discoloration, may be the xcode of the problem bar , I am the problem, the normal switch color will change)

At this time a pod-free multiple target project has been completed, remember to create the file need to check the Lib file, the introduction of a third party also need OH.

17. The above works do not include Pod, but now because of the frequent use of third parties, so a large number of third parties can not be put into the project, the creation of POD also need to note that the first to create a good pod workspace bar, and then bloggers to explain how to configure the Podfile file:

As shown in the figure, each target will be added to the library you need, one can not be less, the completion of your project will be able to introduce AF header file, to this, a complete multi-target project was created, if you are already have the project, the steps are not changed Oh, but to change the state of the check. If you have any questions, you can leave a message or add group discussion.


There is also a pit to forget to say, you may in the compile time said the error, the lack of pod files, do not panic, your pod file, lib file compiled, generate. A file and then compile your project.

Finally, with the main operation of the demo, we can control the next look. Click to go to download

Related Article

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.