Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 了解应用程序是否在测试环境中运行_Objective C_Ios - Fatal编程技术网

Objective c 了解应用程序是否在测试环境中运行

Objective c 了解应用程序是否在测试环境中运行,objective-c,ios,Objective C,Ios,有没有办法知道程序是否在开发环境中运行?我正在使用Flurry Analytics,并希望向其传递一个不同的应用程序id,以便在开发过程中数据不会被我的测试弄脏 我想要的是这样的: Boolean isDevEnv = .... (is this a test in the simulator or device, OR is it a real user that downloaded the

有没有办法知道程序是否在开发环境中运行?我正在使用Flurry Analytics,并希望向其传递一个不同的应用程序id,以便在开发过程中数据不会被我的测试弄脏

我想要的是这样的:

Boolean isDevEnv = .... (is this a test in the simulator or device,
                         OR is it a real user that downloaded the 
                         app through the app store?)
if (isDevEnv)
  [FlurryAnalytics startSession:@"firstAppId"];
else
  [FlurryAnalytics startSession:@"secondAppId"];

很明显,这不是我想要的,因为我使用真实设备和模拟器进行测试。

在构建设置中,为App Store发布版本定义一个新标志。然后使用
#ifdef
在编译时确定要使用哪个appid。

如果不想使用
DEBUG
标志和
DEBUG
环境,请创建新的生成配置(重复版本配置),并在生成设置预处理器宏中添加FlurryAnalytics标志。在代码中检查
if(FlurryAnalytics)
。在XCode中创建一个新方案,使用此新版本生成配置创建ipa。

在生成设置中,您必须根据建筑环境设置标志

然后,使用#ifdef和#define设置appid

#ifdef DEBUG
#    define APPID ...    
#else
#    define APPID ...
#endif

嗯,这似乎是默认情况下由Xode完成的,在项目的构建设置中,在
Apple LLVM compiler 3.1-预处理
(这在Xcode 4.3.2中,供将来参考)下,一个名为
DEBUG
的设置填充了值
1

因此,我实际上不需要做任何事情,只需在代码中这样做(在我的例子中,AppDelegate的
didfishLaunchingwithOptions
方法中):


我可能做了一些愚蠢的错误:在Targets中,我选择了唯一的一个,然后转到Build Settings选项卡,然后添加Build Settings,这会在用户定义的组中添加一行(我将其命名为“TESTING”),然后对于每一行(Debug和Release),我单击加号,我应该在那里输入什么值?
[FlurryAnalytics startSession:DEBUG ? @"firstAppId" : @"secondAppId"];