简体   繁体   English

在iOS模拟器中停用Google Analytics

[英]Disable Google Analytics in iOS simulator

Google Analytics is running in the iOS simulator. Google Analytics正在iOS模拟器中运行。

This causes pollution in the console log which I can be looking for useful debugging information. 这会导致控制台日志中的污染,我可以寻找有用的调试信息。 Also, the data sent to Google is not indicative of an actual user using our app. 此外,发送给Google的数据并不表示使用我们的应用的实际用户。

How can I disable the Google Analytics reporting just while running the app in iOS simulator? 如何在iOS模拟器中运行应用时禁用Google Analytics报告?

Simple, this is taken straight from the Google Analytics webpage : 很简单,这可以直接从Google Analytics网页上获取:

[[GAI sharedInstance] setDryRun:YES];

Dry Run : 干运行:
The SDK provides a dryRun flag that when set, prevents any data from being sent to Google Analytics. SDK提供了一个dryRun标记,该标记在设置时会阻止将任何数据发送到Google Analytics。 The dryRun flag should be set whenever you are testing or debugging an implementation and do not want test data to appear in your Google Analytics reports. 每当您测试或调试实施时,都应设置dryRun标志,并且不希望测试数据显示在您的Google Analytics报告中。

Hope this helps 希望这可以帮助

Yes, Setting DryRun to YES will fix this issue. 是的,将DryRun设置为YES将解决此问题。

@Full Decent - Is there a way to also not have Google Analytics pollute my console logs? @Full Decent - 有没有办法让谷歌分析不会污染我的控制台日志?

We can disable Google Analytics logging in Xcode console using the below method. 我们可以使用以下方法在Xcode控制台中禁用Google Analytics日志记录。

[[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelNone];

Or in Swift: 或者在Swift中:

GAI.sharedInstance().logger.logLevel = GAILogLevel.None

Wrapping it in #if TARGET_IPHONE_SIMULATOR #endif will not work in swift , as that flag is for objective-c only. 将它包装在#if TARGET_IPHONE_SIMULATOR #endif中将无法在swift中工作,因为该标志仅用于objective-c What you could do is follow this guide 你可以做的是遵循本指南

Detect if app is being built for device or simulator in Swift 检测是否正在为Swift中的设备或模拟器构建应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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