Share a non-invasive burial scheme.

The advantage of using a non-intrusive burial point scheme is that the burial point code is decoupled from the business code.

The demo address:Here,

However, many non-invasive burial sites are hook system. For example, some third-party burial sites libraries have the function of automatic burial sites. However, it is difficult to meet the requirements of our project’s customized burial site.

Through this non-intrusive burial point, all the business burial point logic of the whole project can be written into a file.

And this file is not coupled to any business code (let’s take a look at the introduced header)

Please refer to the implementation for details. Because the scheme of non-intrusive burial point is based on the business characteristics of burial point existing in the current project, and the corresponding format is customized, so it is not suitable to be made into the basic component, so the author only gives a demo for your reference.

Principle:

  1. Hook the method of the object to be buried based on the run-time exchange method and the way to dynamically add the method, and then insert the buried point code.
  2. Insertion code can be generated configuratively.
  3. Dynamically deliver A JSON file and dynamically add a buried point.

Currently, two methods can be supported: adding buried points.

A:

  1. Add the object to be exchanged, the method, and the replacement method (hook_className_methodName 🙂

  1. Add the exchange method here. (Note: The parameters must be consistent)

  1. Object properties can be obtained by means of KVC. (Since self is the class to be hooked, it is theoretically possible to retrieve any property of self.) For example:

Method 2:

To add a burial point, add the following configuration under tracker.json.

Notes:

There is a learning atmosphere with a communication circle is particularly important, this is one of my iOS development public number: programming Daxin, whether you are a bull or a small white are welcome to enter, let us progress together, common development!

  1. HookClass is the object of the hook.

  2. HookMethod is the hook method.

  3. Events is the added event, which is of array type. It means that there are multiple buried points in this code. Types, refers array number must be the same as events.

  4. “#0” means take the first argument, “#1” means take the second argument, “#2” means take the third argument, and so on.

  5. Through self. ArticleInfo. ArticleBase. ArticleId obtaining member attributes.

  6. This mode supports only parameters of object types, but does not support basic data types (mode 1 is not restricted).