完全禁用Firebase/Analytics以停止应用程序启动时的控制台垃圾信息

39
我已将 Google/SignIn cocoapod 安装到我的应用程序中(我需要支持 GoogleDrive),但它依赖于 Google/Core,后者又依赖于 FirebaseAnalytics。 我不想也不需要 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

(我必须在上面的输出中添加X,以便通过stackoverflow的URL缩短程序阻止器。)

我尝试在我的Info.plist中将FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED设置为YES,这样就删除了2行,但又添加了另外2行来告诉我分析已被禁用(该死!)。

这种广告式输出使我们的开发人员难以看到实际重要的控制台输出。如何禁用它?

(如果失败,建议如何仅输出每行一次将非常受欢迎。)


@Senseful 不是重复的问题 - 这是关于禁用 Firebase 分析的。不仅仅是禁用日志记录,而是完全停止其运行。 - JosephH
4个回答

58

你可以在输出中找到这个隐藏的内容:

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

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

在此输入图片描述

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

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

或者在Swift中:

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

请查看FIRLogger实现的更多细节 此处


谢谢,这确实帮助我找到了正确的方向 - 尽管 [FIRApp configure] 对我总是抛出一个异常(关于缺少发送者 ID),但似乎它并不是必需的,我尝试了几种添加 -FIRAnalyticsDebugEnabled 到参数列表的变体,但它们都没有真正删除所有 8 行。 - JosephH
1
@ajeetsharma 禁用日志记录不太可能对崩溃产生影响。 - Paul Beusterien
2
对我而言,从所提供的源代码中使用参数“-FIRDebugDisabled”有效。 https://github.com/firebase/firebase-ios-sdk/blob/master/Firebase/Core/FIRLogger.m - Marek Manduch
1
FIRLogger实现的链接无法使用。 - I make my mark
1
对于那些无法使其工作的人,请注意:请按照此处所述使用“-FIRDebugDisabled”:https://dev59.com/-LXna4cB1Zd3GeqPLn30#57334171 - Krøllebølle
显示剩余3条评论

9
据我所知,这两行代码是这样的:

...

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

如果在应用程序委托的didFinishLaunchingWithOptions:非常早的位置放置此代码,将完全禁用FireBase分析,包括停止所有控制台输出。

我还发现Google/SignIn cocoapod已经被弃用了 - 推荐使用的是GoogleSignIn(即没有“/”)。如果使用GoogleSignIn,则它不具有Firebase Analytics的依赖,因此原始问题消失了。现在,我的应用程序支持Google Drive,而且没有Firebase Analytics!


1
@ajeetsharma 这个问题和答案与崩溃无关。如果您遇到了崩溃,那是一个不同的问题,您应该搜索相关的答案或发布一个新的问题。 - JosephH

8

Swift 4.0:

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

在Swift 4.0中:
使用以上代码可设置Firebase日志记录级别为最低,并禁用分析数据收集。

2
你确定 'FirebaseConfiguration.shared.setLoggerLevel(.min)' 语法正确吗? - chb
3
是的,我已经测试过了。 - drfalcoew
12
第二种方法在 Swift 5 和最新的 Firebase 上已不再受支持。 - Alessandro Francucci

2
在Xcode 11.x(Swift 5时代)中:
这可能有点棘手,即使在应用下面的正确解决方案后,您也可能需要重新启动XCode。
  1. 打开Scheme:按COMMAND + SHIFT + <(逗号)以打开Scheme,它将从XCode顶部下降为另一个窗口。
  2. 在左侧选择“Run Debug”
  3. 在窗口顶部选择“Arguments”选项卡
  4. 通过按左下角的小“+”按钮,在“Arguments Passed On Launch”部分中输入以下代码。

(复制粘贴以下内容) -FIRDebugDisabled

这将禁用Firebase的调试模式,包括Firestore、Firebase和Fire Analytics。
如果您还没有加载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文件并将"NO"写入以启用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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接