Detect if App is production version or Development version

时间:2016-04-07 10:55:06

标签: ios objective-c swift

I need to detect at run time whether my apps copy is Production/Development version. Is there any methods to achieve the same.

I am looking forward to develop push notification API which will send APNS messages to server accordingly(i.e. sandbox or without sandbox).

Any help? thanx in advance.

1 个答案:

答案 0 :(得分:9)

在这种情况下,您可以使用条件编译并检查您是否处于调试模式。

在项目设置中,您应该已经定义了一个预处理器宏来指示调试版本:

preprocessor settings

您可以使用它或定义自己的。

您可以在代码中输入

    NSString* platform = @"ios";
#if DEBUG
    platform = @"ios_sandbox";
#endif

#if DEBUG#endif之间的所有内容只会在定义DEBUG=1时编译(在这种情况下仅在调试配置中),所以最后你将在platform中在发布版本中变量ios的值,在调试版本中变量ios_sandbox