当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Enviroment Variables not picked up by code through plist

问题描述:

In my main target .plist file I have this:

<key>HIHomePage</key>

<string>$(MY_BASE_URL)</string>

I'm using a build schema per each environment I have (development, staging, production), so I set MY_BASE_URL in Environment Variables in the build step of the schema.

Then in code I have this:

NSString *baseURL = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"HIHomePage"];

That turns out to be an empty string, however stuff such as CFBundleName is being picked up.

What am I missing here?

网友答案:

To get values from environment variables use the following code

NSString *baseURL = [[[NSProcessInfo processInfo] environment] objectForKey:@"MY_BASE_URL"];

Ref : http://rosettacode.org/wiki/Environment_variables#Objective-C

To add items in plist from scheme, you should dd a user defined build settings with name MY_BASE_URL and enter values as per your scheme. Then use it in .plist file.

For adding user defined build settings, Select target From Editor menu > Add Settings > User defined Settings

分享给朋友:
您可能感兴趣的文章:
随机阅读: