CocoaDebug

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

Github stars Tracking Chart

介绍

  • 摇一摇手机隐藏/显示黑色小球 (支持真机/模拟器)
  • 长按黑色小球显示 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

Main metrics

Overview
Name With OwnerCocoaDebug/CocoaDebug
Primary LanguageSwift
Program languageRuby (Language Count: 5)
PlatformMac
License:
所有者活动
Created At2018-01-15 07:47:38
Pushed At2023-06-11 12:45:10
Last Commit At2023-03-23 23:21:31
Release Count177
Last Release Name1.7.7 (Posted on 2023-03-19 13:11:53)
First Release Name0.0.1 (Posted on 2018-07-07 17:59:18)
用户参与
Stargazers Count4.1k
Watchers Count58
Fork Count390
Commits Count1.1k
Has Issues Enabled
Issues Count124
Issue Open Count50
Pull Requests Count32
Pull Requests Open Count1
Pull Requests Close Count9
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private
中文介绍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.