CocoaDebug

iOS 调试工具。「 ? iOS Debugging Tool 」

Github星跟踪图

介绍

  • 摇一摇手机隐藏/显示黑色小球 (支持真机/模拟器)
  • 长按黑色小球显示 UIDebuggingInformationOverlay (苹果私有方法,支持iOS10/11/12)
  • 内存占用情况,以及 FPS
  • 列出崩溃信息 (可选)
  • 列出 Xcode 里面所有的 print()NSLog() 日志信息 (可选)
  • 列出所有网络请求 (可选)
  • Network Details 页面,可以分享网络日志信息 (通过邮箱/拷贝)
  • 复制日志 (长按文字,选择全选/拷贝)
  • 通过关键字搜索日志
  • 列出 APP 信息和设备信息,包括:version, build, bundle name, bundle id, screen resolution, device, iOS version
  • 列出沙盒所有文件夹和文件,支持预览和编辑
  • 列出 HTML 日志, 包含 console.log(),console.debug(),console.warn(),console.error(),console.info() (支持 WKWebViewUIWebView) (可选)
  • 支持 JSON 和 Google的Protocol buffers

安装

CocoaPods

platform :ios, '8.0'
use_frameworks!

target 'YourTargetName' do
    pod 'CocoaDebug', :configurations => ['Debug']
end
    

Carthage

github "CocoaDebug/CocoaDebug"

警告:不要在将要发布到AppStore的.ipa中导入CocoaDebug.framework。阅读这篇集成指南,了解如何仅在Debug环境下导入CocoaDebug.framework

使用

Swift

//Step 1. (AppDelegate.swift)
#if DEBUG
    import CocoaDebug
#endif
//Step 2. (AppDelegate.swift)
#if DEBUG
    CocoaDebug.enable()
#endif
//Step 3. (AppDelegate.swift)
public func print<T>(file: String = #file, function: String = #function, line: Int = #line, _ message: T, color: UIColor = .white) {
    #if DEBUG
        swiftLog(file, function, line, message, color, false)
    #endif
}

Objective-C

//Step 1. (AppDelegate.m)
#ifdef DEBUG
    @import CocoaDebug;
#endif
//Step 2. (AppDelegate.m)
#ifdef DEBUG
    [CocoaDebug enable];
#endif

更多高级用法,请查看示例代码。

注意:如果项目使用了Swift和Objective-C混编,请小心使用Other Swift FlagsPreprocessor Macros,可以参考这里

参数

初始化CocoaDebug时,可以在CocoaDebug.enable()之前自定义以下这些参数值:

  • serverURL - 如果被抓取的网址包含serverURL,这些网址会被加粗标记。当该参数为nil时,所有网址都不会被加粗标记。默认值为nil
  • ignoredURLs - 设置不被抓取的网址,忽略大小写。当该参数为nil时,抓取所有网址。默认值为nil
  • onlyURLs - 设置被抓取的网址,忽略大小写。当该参数为nil时,抓取所有网址。默认值为nil
  • tabBarControllers - 设置controllers作为UITabBarController的子控制器,默认值为nil
  • logMaxCount - 设置日志显示的最大数值,默认值为1000
  • emailToRecipients - 通过邮件分享日志时,设置收件地址,默认值为nil
  • emailCcRecipients - 通过邮件分享日志时,设置抄送地址,默认值为nil
  • mainColor - 设置CocoaDebug主色调,颜色格式为十六进制。默认值为 #42d459

主要指标

概览
名称与所有者CocoaDebug/CocoaDebug
主编程语言Swift
编程语言Ruby (语言数: 5)
平台Mac
许可证
所有者活动
创建于2018-01-15 07:47:38
推送于2023-06-11 12:45:10
最后一次提交2023-03-23 23:21:31
发布数177
最新版本名称1.7.7 (发布于 2023-03-19 13:11:53)
第一版名称0.0.1 (发布于 2018-07-07 17:59:18)
用户参与
星数4.1k
关注者数58
派生数390
提交数1.1k
已启用问题?
问题数124
打开的问题数50
拉请求数32
打开的拉请求数1
关闭的拉请求数9
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?
中文介绍IntroductionInstallationUsageParameters
Travis CI Build Status
Codacy Codacy Badge
Codecov codecov
Frameworks Carthage Compatible CocoaPods Compatible
Languages Languages
Platform Platform
Licence

Introduction

example

  • Shake to hide or show the black bubble. (support both device and simulator)

  • Long press the black bubble to show UIDebuggingInformationOverlay. (Apple's Private API, support iOS 10/11/12)

  • Application memory usage and FPS.

  • List all print() and NSLog() messages which have been written by developer in Xcode.

  • List of all the network requests sent by the application.

  • List crash errors.

  • Share network details via email or copy to clipboard when you are in the Network Details page.

  • Copy logs. (long press the text, then select all or select copy)

  • Search logs by keyword.

  • List application and device informations, including: version, build, bundle name, bundle id, screen resolution, device, iOS version

  • List all sandbox folders and files, supporting to preview and edit.

  • List HTML logs, including console.log(),console.debug(),console.warn(),console.error(),console. info(). (support both WKWebView and UIWebView).

  • Support JSON and Google's Protocol buffers

Installation

CocoaPods

target 'YourTargetName' do
    pod 'CocoaDebug', :configurations => ['Debug']
end

Carthage

github "CocoaDebug/CocoaDebug"

Framework

Download

WARNING: Don't submit .ipa to AppStore which has been linked with the CocoaDebug.framework. This Integration Guide outline a way to use build configurations to isolate linking the framework to Debug builds only.

Usage

Swift

//AppDelegate.swift
 
#if DEBUG
    import CocoaDebug
#endif

#if DEBUG
    CocoaDebug.enable()
#endif

public func print<T>(file: String = #file, function: String = #function, line: Int = #line, _ message: T, color: UIColor = .white) {
    #if DEBUG
        swiftLog(file, function, line, message, color, false)
    #endif
}

Objective-C

//AppDelegate.m
 
#ifdef DEBUG
    @import CocoaDebug;
#endif

#ifdef DEBUG
    [CocoaDebug enable];
#endif

Please check Example_Swift.xcodeproj and Example_Objc.xcodeproj for more advanced usage.

NOTE: Be careful with Other Swift Flags & Preprocessor Macros when using Swift & Objective-C in one project. You can refer to here.

Parameters

When you initialize CocoaDebug, you can customize the following parameter values before CocoaDebug.enable().

  • serverURL - If the crawled URLs contain server URL ,set these URLs bold font to be marked. not mark when this value is nil. default value is nil.

  • ignoredURLs - Set the URLs which should not crawled, ignoring case, crawl all URLs when the value is nil. default value is nil.

  • onlyURLs - Set the URLs which are only crawled, ignoring case, crawl all URLs when the value is nil. default value is nil.

  • tabBarControllers - Set controllers to be added as child controllers of UITabBarController. default value is nil.

  • logMaxCount - The maximum count of logs which CocoaDebug display. default value is 1000.

  • emailToRecipients - Set the initial recipients to include in the email’s “To” field when share via email. default value is nil.

  • emailCcRecipients - Set the initial recipients to include in the email’s “Cc” field when share via email. default value is nil.

  • mainColor - Set the main color with hexadecimal format. default value is #42d459.

TODO

Thanks

Special thanks to remirobert.

License

CocoaDebug is released under the MIT license.