完全禁用Firebase / Analytics以在应用启动时停止控制台垃圾邮件

时间:2017-06-07 17:21:06

标签: ios firebase firebase-analytics

我已将Google / SignIn cocoapod安装到我的应用程序中(我需要支持GoogleDrive),但这取决于依赖于FirebaseAnalytics的Google / Core。我不想要或不需要FirebaseAnalytics。

当我们的应用启动时,FirebaseAnalytics会使开发人员控制台发出8行输出:

2017-06-07 18:07:19.612994+0100 son[2909:877661] [Firebase/Analytics][I-ACS005000] The AdSupport Framework is not currently linked. Some features will not function properly. Learn more at http://gooX.gl/9vSsPb
2017-06-07 18:07:19.613 son[2909] <Warning> [Firebase/Analytics][I-ACS005000] The AdSupport Framework is not currently linked. Some features will not function properly. Learn more at http://gooX.gl/9vSsPb
2017-06-07 18:07:19.613896+0100 son[2909:877661] [Firebase/Analytics][I-ACS023007] Firebase Analytics v.3900000 started
2017-06-07 18:07:19.614 son[2909] <Notice> [Firebase/Analytics][I-ACS023007] Firebase Analytics v.3900000 started
2017-06-07 18:07:19.614525+0100 son[2909:877661] [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://gooX.gl/RfcP7r)
2017-06-07 18:07:19.614 son[2909] <Notice> [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://gooX.gl/RfcP7r)
2017-06-07 18:07:19.622560+0100 son[2909:877662] [Firebase/Analytics][I-ACS023013] Firebase Analytics disabled
2017-06-07 18:07:19.623 son[2909] <Notice> [Firebase/Analytics][I-ACS023013] Firebase Analytics disabled

(我不得不在上面输出的URL中添加X以通过stackoverflow的URL缩短阻止程序。)

我尝试在我的Info.plist中将FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED设置为YES,删除了2行,但添加了另外2行,告诉我Google Analytics已禁用(FFS!)。

这种垃圾邮件输出使我们的开发人员很难看到任何实际重要的控制台输出。我该如何禁用它?

(如果不这样做,关于如何让它只输出一行的建议将非常受欢迎。)

4 个答案:

答案 0 :(得分:19)

你可以在输出中找到这个:

<Notice> [Firebase/Analytics][I-ACS023008] To enable debug logging
 set the following application argument: -FIRAnalyticsDebugEnabled

禁用是相反的 - 设置参数:-noFIRAnalyticsDebugEnabled:

enter image description here

此外,您可以使用FIRConfiguration中的setLoggerLevel方法控制默认的Firebase日志记录级别。例如,要禁用所有Firebase日志记录:

  [[FIRConfiguration sharedInstance] setLoggerLevel:FIRLoggerLevelMin];
  [FIRApp configure];

或在Swift中:

FirebaseConfiguration.shared.setLoggerLevel(FirebaseLoggerLevel.min)
FirebaseApp.configure()

FIRLogger实施中的更多细节here

答案 1 :(得分:5)

据我所知,这两行:

[[FIRConfiguration sharedInstance] setLoggerLevel:FIRLoggerLevelMin];
[[FIRAnalyticsConfiguration sharedInstance] setAnalyticsCollectionEnabled:NO];

非常早地放置在应用代理中didFinishLaunchingWithOptions:将完全禁用FireBase分析,包括停止所有控制台输出。

我也发现Google/SignIn cocoapod已被弃用 - 推荐使用的是GoogleSignIn(即没有&#39; /&#39;)。如果您使用GoogleSignIn,那么这并不依赖于Firebase Analytics,因此原始问题就会消失。现在我在我的应用中获得了Google云端硬盘支持,并且没有Firebase Analytics!

答案 2 :(得分:1)

Swift 4.0:

FirebaseConfiguration.shared.setLoggerLevel(.min) FirebaseConfiguration.shared.analyticsConfiguration.setAnalyticsCollectionEnabled(false)

答案 3 :(得分:0)

在 Xcode 11.x(Swift 5 时代):

这个可能有点麻烦,即使应用了下面的正确解决方案,您也可能需要重新启动 XCode。

  1. 打开方案:按 COMMAND + SHIFT + <(逗号)打开方案,该方案将从 XCode 顶部作为另一个窗口下拉。
  2. 在左侧选择“运行调试”
  3. 选择窗口顶部的“参数”选项卡
  4. 按下左下角的小“+”按钮,将下面的代码输入到“启动时传递的参数”部分。

(复制粘贴这个) -FIRDebugDisabled

这将为 Firestore、Firebase 和 Fire Analytics 禁用 Firebase 的调试模式。

如果您还没有加载 Fire Analytics,那么您只需在 AppDelegate.swift 文件中输入以下代码:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
    FirebaseApp.configure()
    let db = Firestore.firestore()


    // This below is the line of code to enter, but it won't stop Firebase Analytics from printing its mess in the consoleLog, but this works if you're not using FireBase Analytics.
    FirebaseConfiguration.shared.setLoggerLevel(.min)

    return true
}

注意/附加:您可以打开您的 Google info.plist 并写“否”以启用 Firebase。要获取Google 的info.plist,只需单击info.plist 文件,然后在导航窗口的顶部单击info.plist,它将打开一个选择器,其中Google 的info.plist 作为可选项目。见图 2。

图 1:下拉菜单的样子。 enter image description here

图 2:Google 的 info.plist enter image description here