简体   繁体   中英

How to create dev/staging/production environments

I'm trying to create an Xcode project that works in a development environment (using the computer as a local host), staging environment (a specific endpoint on a server), and a production environment (another specific server endpoint). I have found a few different tutorials about how to set this up. Some solutions suggest creating different target, some suggest creating different configurations. What is the most effective way to do this?

Following are the steps to create different schemes

  1. Select the target
  2. Create new scheme and give specific name to scheme (Dev,Staging,Prod,Debug)

i have attached screen shot for your reference

Sample Screen Shot for reference

在此输入图像描述

if you want to set different url for different schemes then do the following steps:

1.Go to Build Setting

2.Go to user defined section

3.Create macros and specify urls for each environment

1. Duplicate your current project Target and rename like DEV/QA/PROD.

2. Add New Environment.plist into your project. Structure of Environment.plist will be like below. 在此输入图像描述

3. In your service class add method to fetch baseURL according to your target settings. Eg Code:

 NSURL* environmentsURL = [[NSBundle mainBundle] URLForResource:@"Environments" withExtension:@"plist"]; NSDictionary* environments = [NSDictionary dictionaryWithContentsOfURL:environmentsURL]; NSString* currentEnvironment = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"Environment"]; NSString* keyPath = [NSString stringWithFormat:@"%@.baseURL", currentEnvironment]; NSString *baseUrlString = [environments valueForKeyPath:keyPath]; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM