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:
- 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.
- Insertion code can be generated configuratively.
- Dynamically deliver A JSON file and dynamically add a buried point.
Currently, two methods can be supported: adding buried points.
A:
- Add the object to be exchanged, the method, and the replacement method (hook_className_methodName 🙂
- Add the exchange method here. (Note: The parameters must be consistent)
-
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!
-
HookClass is the object of the hook.
-
HookMethod is the hook method.
-
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.
-
“#0” means take the first argument, “#1” means take the second argument, “#2” means take the third argument, and so on.
-
Through self. ArticleInfo. ArticleBase. ArticleId obtaining member attributes.
-
This mode supports only parameters of object types, but does not support basic data types (mode 1 is not restricted).