Migrate old articles to dig for gold

preface

This tool in the early VKDebugConsole on the basis of completely overthrew the redo, the core ideas are the same, just rearrange the tool to use the way, tool interface presentation, tool module division, modular extensible support

Old Document link – VKDebugConsole App black box console

VKDevTooL

Github VKDevTool is an in-app debugging tool

Allows for the

  • Without Xcode Debug
  • In the case of a real black box

Conduct App debugging, including:

  • Debugging memory objects
  • Print memory data
  • Modify the UI
  • Check the NSLog
  • View all network request records
  • View the App interface hierarchy

In the environment of black box test and internal experience, it is convenient to directly debug memory and analyze problems in the field of bugs when bugs are found

Used to introduce

Project configuration

  • willVKDevToolDrag folders into project files
  • willVKDevToolLogHeader.hWrite the PCH to enable the dynamic interception record of NSLog. The NSLog cannot be captured without importing the ConsoleLog module
  • You can modifyVKDevToolDefine.hIn the#ifdef DEBUGTo customize the compilation control. If you do not modify it, the VKDevTool works in default Debug mode

Write the code

[VKDevTool enableDebugMode];
Copy the code

One line of code enables DevTool, which has built-in build control and automatically disables the Release version, without requiring the user to put #ifdef DEBUG around the line of code

How to use

After completing the project configuration and writing the code, you can open the project mode menu in the App in the following way

  • In the simulator, use the keyboard command+ X shortcut keys to invoke the menu
  • When the real machine is running, use shake to evoke the menu

The main menu module contains four modules

  • DebugScript
  • ConsoleLog
  • NetworkLog
  • ViewHierarchy3D

VKDevTool adopts a modular design, each Module can be separated independently, while supporting user-defined extension of their own modules, the additional two modules in the figure are customized modules

Black box debugging function DebugScript

  • Select from the main menuDebugScript
  • Click the prompt to select any interface element
  • Go to the code console
  • Above is the code entry box
  • Below is the output box

JSPatch syntax: JSPatch syntax: JSPatch syntax: JSPatch syntax

  • A shake of the or simulator Command+X can evoke the DebugScript module submenu
  • If you enter Command+X in the emulator, it may not work. Use the emulator menuShake GestureFunction simulates a shake, still can arouse

The submenu contains the following functions

  • GetTarget: Automatically input GetTarget script code into the input box, execute the later print Target information, facilitate the subsequent direct debugging of Target arbitrary memory data and execution method

  • Get TargetVC: automatically input getTargetVC script code into the input box, and execute the current VC information of the print Target, which is convenient for the subsequent direct debugging of any memory data and execution method of TargetVC

  • ChangeTarget: The system automatically enters the code for switching the selected target in the input box. After the code is executed, the system returns to the target selection screen

  • ClearInput: Clears the input area

  • ClearOutput: Clears the output area

  • Exit, Exit DebugScript

In addition, the DebugScript adds a function print() to the JS code, which can print any OC object, and if the object is a View, additional frame and other information will be output

GIF is an old GIF, the new version of the color style has been adjusted, add submenu shortcuts, but the usage is completely the same

Log interception ConsoleLog

After adding vkDevToolLogHeader. h to PCH, this module will intercept all NSLog printed logs and NSError generated records and display them in this interface

  • NSLog records intercept all NSLog requests in the form of macro overwriting and are displayed in white on the interface.
  • NSError records use Runtime Swizzle to intercept NSError init and are displayed in red

A shake of the or simulator Command+X evokes the console elog module submenu

  • NSError Hook: Enables or disables NSError intercepting
  • Copy to Pasteboard: Copies all log information to a Pasteboard
  • Search Keyword: Searches for keywords in many logs. Keywords are shown in blue
  • Exit, Exit

Network interception NetworkLog

VKDevTool uses NSURLProtocol to intercept hook all HTTP requests and record them one by one, presenting them in a list in NetworkLog module

Each cell can be clicked to see the actual returned data for each network request and can be copied to the clipboard

A shake of the or simulator Command+X can evoke the NetworkLog module submenu

  • Network Hook: You can enable or disable HTTP interception
  • Change Filter: Filters network requests containing fixed strings, facilitating search
  • Exit, Exit

If NetworkHook is invalid, check if AFN sessionManager needs to register NSURLProtocol

NSURLSessionConfiguration *configuration= [NSURLSessionConfiguration defaultSessionConfiguration];

NSArray *protocolArray = @[[VKURLProtocol class]];

configuration.protocolClasses = protocolArray

Copy the code

Page level ViewHierarchy3D

VKDevTool adopts YY Daishen open source YYViewHierarchy3D to achieve this page level module

  • A real shake or simulator Command+X can evoke the ViewHierarchy3D module submenu
  • Command+X may not work in the emulator. Use the emulator menuShake GestureFunction simulates a shake, still can arouse

Other extension code

[VKDevTool changeNetworktModuleFilter: @ "XXXXX"];Copy the code

This interface controls the filter of the network request HookLog and only intercepts HTTP network requests containing XXXX strings. In DevTool, you can also modify the filter of the network interception through the menu

If all are intercepted, they can be omitted

[VKDevTool registKeyName:@"custom module name" withExtensionFunction:^{
    //todo your code
}];
Copy the code

VKDevTool adopts a modular design, each Module can be separated independently, while supporting user-defined extension of their own modules

This interface is used to extend the main menu module of VKDevTool.