iPhone - Switching between local and production environment settings

泄露秘密 提交于 2019-12-05 05:25:22

In one of your header files (such as the pre-compiled header file) define macros with the URL. Take a look at this article and use a similar approach.

Incidentally, I'm using the logging approach from this article in all my apps - it works like a charm, I strongly recommend it!

Put this code where you need to use the configuration based on the mode (debug/release) = (development/production).

The best place to put it is on the "ProjectName"_Prefix.pch file.

#ifndef __OPTIMIZE__ // __OPTIMIZE__ is not enabled, it means that the active config is Debug, so here you have to put your code for development mode

// For example
#define SERVER_URL @"http://my.test.server/something"

#else //__OPTIMIZE__ is defined, so put here your production code

// For example
#define SERVER_URL @"http://my.production.server/something"

#endif // __OPTIMIZE__

Cheers,
VFN

You can define pre-proccessor macros in xcode by simply editing the gcc language settings:

Go to the Project menu and select "Edit Project Settings". Go to the "Build" tab .

Go to the section labeled "GCC 4.0 - Language". There is a setting named "Other C Flags". Add all the "-Dwhatever" macros you want there.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!