You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SwiftUI项目中如何隐藏/停止Xcode控制台输出的GTMSessionFetcher日志

隐藏Xcode控制台GTMSessionFetcher输出日志的方案

针对以下类型的GTMSessionFetcher调试日志:

GTMSessionFetcher invoking fetch callbacks, data {length = 2270, bytes = 0x7b227265 73756c74 223a7b22 72657375 ... 52696465 73227d7d }, error (null)

日志截图

可通过以下几种方式关闭:

方法1:添加环境变量(无需修改代码,立即生效)

  • 按快捷键Cmd + <打开Xcode Scheme编辑页,或点击顶部菜单栏Product > Scheme > Edit Scheme
  • 左侧选中Run选项,切换到Arguments标签
  • 在Environment Variables区域点击+号,添加变量:
    • 变量名:GIDLoggingLevel
    • 变量值:0
  • 保存后重新运行项目即可

方法2:代码中全局关闭日志

在App启动入口(如application:didFinishLaunchingWithOptions:)中添加代码:

// Objective-C 写法
[GTMSessionFetcher setLoggingEnabled:NO];
// 若为Google登录依赖引入,可额外添加
[GIDSignIn sharedInstance].logLevel = kGIDSignInLogLevelNone;
// Swift 写法
GTMSessionFetcher.setLoggingEnabled(false)
// 若为Google登录依赖引入,可额外添加
GIDSignIn.sharedInstance().logLevel = .none

方法3:Release包彻底移除日志(CocoaPods集成场景)

如果通过CocoaPods引入GTMSessionFetcher,可在Podfile中添加如下配置,在Release编译时彻底移除日志代码:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    next unless target.name == 'GTMSessionFetcher'
    target.build_configurations.each do |config|
      next unless config.name == 'Release'
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'GTM_DISABLE_LOGGING=1']
    end
  end
end

配置完成后执行pod install重新集成即可。

内容的提问来源于stack exchange,提问作者Sham Dhiman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 13:09:01