The following configuration is invalid under the SWIFT project, so the blogger has confirmed a slight difference between SWIFT configuration and OC through research and practice. If you are a SWIFT project, please move to swift version:Click to
I wonder if you need to pack often? All kinds of packages, test server, official server, development server and so on, every time need to annotate open different domain name, sometimes accidentally forget and may cause a lot of loss, how to standardize to manage these environments? You can switch between different environments by selecting the target:
1. Let’s create an empty project called Hello.
2. After creating the project, right-click our target:
3. We assume that we need the formal environment, the development environment and the test environment. The original target is the formal environment.
4. When you get to this point, you create it and rename it:
5. Change the name of the plist file, and then go back to the corresponding target file. Button to select the corresponding PList file.
After that, it is not convenient to check multiple times when creating a file because there are three targets:
6. Create a lib file to manage:
7. Click open and drag to bottom:
8. Click Next and type in the name HelloLib, then select Target:
9. Add the newly created lib
10. You’ll notice that target names in Schemes don’t correspond yet:
11. Delete all the items here and press “-“. After deleting, click “+” again to come out, delete several times to add several times oh.
When you’re done, close it and create a new file, check lib, don’t check Target, but don’t touch the Appdelegate file, because this is the origin. Of course, if you check Lib, don’t check target
Note here, only m files can be checked, h files can not oh.
13. We are not finished here, we have created different environments, but we have not configured different domain names after selecting the corresponding target. Enter Preprocessing in build Setting:
Dev =1, TEST=1, Dev =1, TEST=1, Dev =1, TEST=1, Dev =1, TEST=1
15. When you’re done, go to Appdelegate, in a method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ #ifdef DEBUG url = @"http://bbbbbbbbbbbbbbb"; #elif DEV url = @"http://cccccccccccccc"; #elif TEST url = @"http://dddddddddddddd"; #endif #endif #endif #endif #endifCopy the code
16. You can switch target in Schemes to see which target and which definition of URL has color (after switching target, you need to switch file back and forth to see the color change of the URL, otherwise the color change of the previous URL is probably Xcode’s problem. The color will change after normal switching) \
At this time, a multi-target project without POD has been completed, remember to create files need to check the lib file, also need to introduce a third party oh. \
This project does not include a pod, but it is now used frequently by third parties. Therefore, it is not possible to put a pod into the project by third parties.
As shown in the figure, each target should add the library you need, no less than one, after completion of your project can introduce the AF header file, by this point, a complete multi-target project is created, if you have an existing project, the step is the same, but change the check state. Have a question can leave a message or add group discussion oh.
There is also a hole that you forgot to mention, you may say error when compiling, pod file is missing, don’t panic, your pod file, lib file to compile, and then compile your project.
Finally attached to the blogger operation Demo, we can compare to see. Click to download