CN111309407A - Processing method and device for integrated third-party library - Google Patents

Processing method and device for integrated third-party library Download PDF

Info

Publication number
CN111309407A
CN111309407A CN202010108828.4A CN202010108828A CN111309407A CN 111309407 A CN111309407 A CN 111309407A CN 202010108828 A CN202010108828 A CN 202010108828A CN 111309407 A CN111309407 A CN 111309407A
Authority
CN
China
Prior art keywords
party application
party
class
function
parameter
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010108828.4A
Other languages
Chinese (zh)
Other versions
CN111309407B (en
Inventor
唐鹏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Mobile Communications Group Co Ltd
MIGU Culture Technology Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
MIGU Culture Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Mobile Communications Group Co Ltd, MIGU Culture Technology Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN202010108828.4A priority Critical patent/CN111309407B/en
Publication of CN111309407A publication Critical patent/CN111309407A/en
Application granted granted Critical
Publication of CN111309407B publication Critical patent/CN111309407B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • G06F9/4484Executing subprograms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4488Object-oriented
    • G06F9/449Object-oriented method invocation or resolution
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The embodiment of the invention provides a processing method and a device for integrating a third-party library, wherein the method comprises the following steps: dynamically calling a first method used for registering a third-party application in a class of the third-party application inside the SDK, wherein the third-party application is determined according to identification information transmitted by a target application program; sending an authorization request to a server of the third-party application by dynamically calling a second method in the class of the third-party application, so that the server of the third-party application returns parameters related to the function of the third-party application to the target application program; and calling back parameters which are transmitted from the target application program and are related to the functions of the third-party application by dynamically calling a third-party method in the class of the third-party application. According to the embodiment of the invention, the function of the third-party library is used as required, and all the third-party libraries are not required to be introduced into the engineering, so that the workload of client integration is effectively reduced, and the size of the APP inclusion is reduced.

Description

Processing method and device for integrated third-party library
Technical Field
The invention relates to the technical field of computers, in particular to a processing method and device for integrating a third-party library.
Background
When the third-party library is integrated in the IOS-SDK, the method in the third-party library is called, and therefore, a header file of the third-party library needs to be introduced, so that the corresponding function method can be found. For example, when the authorized login function of the WeChat is integrated, a WXApi.h header file needs to be introduced into the code, and then the compiling is successful. When the application program APP uses the IOS-SDK, the APPID and the APPKey of the third-party application to be used are transmitted into the IOS-SDK, and a corresponding third-party SDK library is introduced into the Xcode engineering file, so that the authorized login function of the third-party application can be used by one key.
If the IOS-SDK has the functions of multiple third-party applications such as QQ, WeChat, microblog and Paibao at the same time, but a calling party only needs to use one or a combination of the functions of the third-party applications, if the existing technical scheme that the third-party SDK library function can be used by introducing a third-party header file is used, the SDK libraries of all the third-party applications need to be introduced into the Xcode engineering file, otherwise, the header file introduced into the IOS-SDK reports that the compiling error of the corresponding method cannot be found. The problems that this brings are mainly two-fold: one is that the workload of client integration is increased, and unnecessary third-party SDK libraries are introduced; the second is to increase the packet size of APP, since some third party SDK libraries that do not need to be used are also compiled.
Disclosure of Invention
In order to solve the problems that the client integration workload is large and the APP inclusion is large due to the fact that only a third-party head file needs to be introduced into an IOS-SDK to use a third-party SDK library function, the embodiment of the invention provides a processing method and a processing device for integrating a third-party library.
In a first aspect, an embodiment of the present invention provides a processing method for integrating a third-party library, including:
dynamically calling a first method for registering a third-party application in a class of the third-party application in a Software Development Kit (SDK), wherein the third-party application is determined according to identification information transmitted by a target application program;
sending an authorization request to a server of the third-party application by dynamically calling a second method in the class of the third-party application, so that the server of the third-party application returns parameters related to the function of the third-party application to the target application program;
and calling back parameters which are transmitted from the target application program and are related to the functions of the third-party application by dynamically calling a third-party method in the class of the third-party application.
The method comprises the following steps that a first method for registering a third-party application in a class of the third-party application is dynamically called in the software development kit SDK, and specifically comprises the following steps:
dynamically generating the first method;
if the first method exists in the instantiation object of the class of the third-party application, the first method is found, and the first method is instantiated by taking the identification information as the entry parameter of the first method.
Before the dynamically calling the second method in the class of the third-party application, the method further includes:
and determining that the third-party application is installed on the user terminal by dynamically calling a fourth method in the class of the third-party application.
Sending an authorization request to a server of the third-party application by dynamically calling a second method in the class of the third-party application, so that the server of the third-party application returns parameters related to the function of the third-party application to the target application program, specifically:
dynamically generating the second method;
if the second method is determined to exist in the instantiation object of the class of the third-party application, the second method is found;
and taking the type of the parameter related to the function of the third-party application and the position returned by the parameter, which need to be acquired, as the input parameters of the second method, and instantiating the second method, so that the server of the third-party application returns the parameter related to the function of the third-party application to the target application program according to the type of the parameter and the position returned by the parameter.
The step of instantiating the second method by taking the type of the parameter related to the function of the third-party application, which needs to be acquired, and the position where the parameter is returned as the input of the second method, so that the server of the third-party application returns the parameter related to the function of the third-party application to the target application program according to the type of the parameter and the position where the parameter is returned, specifically includes:
capturing an authorization request sending pointer in the target application program by using a character string construction class instance function, and if the authorization request sending pointer is captured, constructing an authorization request sending class object, wherein the authorization request sending class object is used for indicating the type of the parameter which needs to be acquired and is related to the function of the third-party application;
and taking the authorization request sending class object, the parameter returning position and the self parameter as the entry parameters of the second method, and instantiating the second method, so that the server of the third-party application returns the parameter related to the function of the third-party application to the target application program according to the authorization request sending class object, the parameter returning position and the self parameter.
The method comprises the following steps of dynamically calling a third-party method in the class of the third-party application, and calling back parameters which are transmitted from the target application program and are related to the function of the third-party application, wherein the parameters specifically comprise:
dynamically generating the third method;
if the third method exists in the instantiation objects of the class of the third-party application, the third method is found, and the third method is instantiated by taking the parameters which are transmitted from the target application program and are related to the function of the third-party application as the input parameters of the third method.
Wherein, after the step of calling back the parameters related to the function of the third-party application, which are transmitted from the target application program, the method further comprises the following steps:
analyzing parameters related to the function of the third-party application by calling a callback function, and acquiring user data related to the function of the third-party application;
and uploading the user data to a uniform user center background to obtain corresponding user information and a user unique identifier, and returning the user information and the user unique identifier to the target application program.
In a second aspect, an embodiment of the present invention provides a processing apparatus for integrating a third-party library, including:
the third-party application registration module is used for calling a first method for registering the third-party application in a class of the third-party application, wherein the third-party application is determined according to identification information transmitted by a target application program;
the dynamic authorization module is used for sending an authorization request to a server of the third-party application by dynamically calling a second method in the class of the third-party application so as to enable the server of the third-party application to return parameters related to the function of the third-party application to the target application program;
and the parameter callback module is used for calling back the parameters which are transmitted from the target application program and are related to the functions of the third-party application by dynamically calling the third-party methods in the class of the third-party application.
In a third aspect, an embodiment of the present invention provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, where the processor implements the steps of the processing method for integrating a third-party library as provided in the first aspect when executing the program.
In a fourth aspect, an embodiment of the present invention provides a non-transitory computer readable storage medium, on which a computer program is stored, which when executed by a processor, implements the steps of the processing method of integrating third party libraries as provided in the first aspect.
The processing method and the device for integrating the third-party library, provided by the embodiment of the invention, solve the problem that the IOS-SDK can use the third-party library function only by introducing the header file by using the dynamic calling mechanism, so that the IOS-SDK and the APP can use the function of the third-party library as required without depending on the existence of the third-party library during compiling, and all the third-party libraries do not need to be introduced into the engineering, thereby effectively reducing the workload of client integration and simultaneously reducing the size of the packet body of the APP.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
Fig. 1 is a schematic flowchart of a processing method for integrating a third-party library according to an embodiment of the present invention;
FIG. 2 is a schematic flow chart illustrating a WeChat authorization login function implemented by dynamically integrating a third-party library according to an embodiment of the present invention;
FIG. 3 is a schematic structural diagram of a processing device integrated with a third-party library according to an embodiment of the present invention;
fig. 4 is a schematic physical structure diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
As shown in fig. 1, a schematic flow chart of a processing method for integrating a third party library according to an embodiment of the present invention includes:
step 100, dynamically calling a first method for registering a third-party application in a class of the third-party application in a Software Development Kit (SDK), wherein the third-party application is determined according to identification information transmitted by a target application program;
specifically, the execution subject of the embodiment of the present invention is a software development kit SDK, and in order to integrate the function of the third-party application in the target application APP, a runtime mechanism in the IOS is utilized, that is, corresponding classes and methods are dynamically loaded when the target application runs, and it is not necessary to introduce all the third-party libraries into the project.
Third party applications include, but are not limited to: APP such as WeChat, Payment treasured, microblog and QQ, and functions of third party application include but are not limited to functions such as authorized login function, payment function, sharing function.
In the embodiment of the invention, firstly, the third-party application selected by the user at the target application program APP client side is determined, specifically, the third-party application selected by the user is determined according to the identification information transmitted by the target application program, then the class related to the function of integrating the third-party application is dynamically loaded, and for convenience of description, the class related to the function of integrating the third-party application is simply referred to as the class of the third-party application.
In one embodiment, if a value of a parameter transmission interface of a third-party application provided for a target application program APP client is detected to be transmitted, a class of the third-party application is dynamically loaded; wherein the value is specifically identification information of the third-party application. For example, if it is detected that a value is introduced into a wechat parameter interface provided for the target application program APP client, it is determined that the third-party application selected by the user is wechat, and the value is an APPID of the wechat, and then the wechat-like WXApi is dynamically loaded.
In order to call the function in the class of the third-party application, the class of the third-party application needs to be instantiated, and then the instantiated object of the class of the third-party application is used for dynamically calling the function in the class of the third-party application. In the embodiment of the present invention, the dynamically loading the class of the third-party application specifically includes:
constructing a class instance function by using the character string to capture a pointer of the class of the third-party application;
and if the pointer of the class of the third-party application is captured, determining that the instantiation object of the class of the third-party application exists.
The example function of the character string construction class can be an NSClassFromString function, and the NSClassFromString function can directly obtain a class from the character string, so that the dynamic loading of the class is realized. And capturing a pointer of the class of the third-party application by using a character string construction class instance function, wherein specific codes can be expressed as:
Class*wxClass=NSClassFromString(@“WXApi”)
if the pointer wxClass to the class of the third party application can be captured (hook), it is indicated that an instantiated object of the class of the third party application exists.
After the instantiation object of the class of the third-party application is determined to exist, the SDK registers the third-party application by dynamically calling the first method in the class of the third-party application.
Step 101, sending an authorization request to a server of the third-party application by dynamically calling a second method in the class of the third-party application, so that the server of the third-party application returns parameters related to the function of the third-party application to the target application program;
specifically, after the third-party application is registered, the SDK realizes sending an authorization request to a server of the third-party application by dynamically calling a second method in the class of the third-party application; after the authorization request is sent, jumping to a client side of the third-party application, after a user confirms authorization, a server of the third-party application returns parameters related to the functions of the third-party application to the target application program, and then the target application program transmits the parameters related to the functions of the third-party application into the SDK through a parameter transmission interface of the third-party application provided by the SDK.
It should be noted that, in the embodiment of the present invention, the default user terminal is a client terminal on which the third-party application is installed. In one embodiment, the authorization request carries the type of parameters needed to integrate the functionality of the third party application and the location of the parameter return.
And 102, calling back parameters which are transmitted from the target application program and are related to the functions of the third-party application by dynamically calling a third-party method in the class of the third-party application.
Specifically, the SDK dynamically invokes a third method, where the third method is used to call back a parameter, which is transmitted from the target application program and returned by the server of the third-party application.
The SDK obtains the parameter returned by the server of the third-party application, that is, obtains the authorization of the third-party application, and may use the parameter to implement the function of the third-party application.
The processing method for integrating the third-party library provided by the embodiment of the invention solves the problem that the IOS-SDK can use the function of the third-party library only by introducing the header file through a dynamic calling mechanism, so that the IOS-SDK and the APP can use the function of the third-party library as required without depending on the existence of the third-party library during compiling, all the third-party libraries do not need to be introduced into a project, the workload of client integration is effectively reduced, and the size of the packet of the APP is reduced.
Based on the content of the above embodiment, the first method for registering the third-party application in the class of the third-party application dynamically invoked by the software development kit SDK specifically includes:
dynamically generating the first method;
if the first method exists in the instantiation object of the class of the third-party application, the first method is found, and the first method is instantiated by taking the identification information as the entry parameter of the first method.
Specifically, firstly, a character string is used for constructing a class instance function, a pointer of a class of the third-party application is captured when the target application program runs, and if the pointer of the class of the third-party application is captured, it is determined that an instantiation object of the class of the third-party application exists.
Then, a first method for registering the function of the third-party application is dynamically generated, and whether the first method exists in a method table pointed by the pointer of the class of the third-party application is judged.
In one embodiment, the first method is dynamically generated by using a string acquisition selector function, the string acquisition selector function is specifically an nsselectorfromstering function, and the nsselectorfromstering function can directly acquire a selector from a string, so that dynamic loading of the method is realized. Namely, a first method for dynamically generating a function for registering the third party application by using the NSSelectorFromString function, and determining whether the first method exists in a method table pointed to by a pointer of a class of the third party application by using a respondtoselector function.
If the first method exists in the method table pointed by the pointer of the class of the third-party application, the pointer corresponding to the first method is found, the identification information of the third-party application is used as the input parameter of the first method, and the first method is instantiated according to the pointer, so that the identification information of the third-party application is transmitted to the first method, and the function of the third-party application is registered. In one embodiment, the first method is found using the obj c _ msgSend assembly function. Parameter transmission is realized by utilizing the objc _ msgSend assembly function, the efficiency is high, the safety is high, and the decoding is not easy to crack.
Taking the implementation of the WeChat authorized login function as an example, detecting that a WeChat parameter transmission interface has a value to be transmitted into the SDK, using an NSClassFromString method to actively control a WXApi class pointer wxClass in a hook application when the APP runs, if the object cannot be instantiated, indicating that the wxClass does not exist, returning failure, and terminating the step. If the method exists, NSSelectorFormString is continuously used for generating a register App, namely a dynamic method SEL1, then a respondToSelector is used for judging whether a SEL1 method exists in a method table pointed by wxClass, if the method does not exist, a failure termination step is returned, if the method exists, a pointer corresponding to the SEL1 method is found in the method table pointed by objc _ msgSend to wxClass, the method is instantiated according to the pointer, and the APPID is transmitted to register the WeChat authorization login function. The above process may be implemented by the following pseudo code:
Figure BDA0002389256620000091
according to the processing method and device for the integrated third-party library, parameter transmission is achieved through the dynamic calling mechanism and the obj _ msgSend assembly function, so that a function method to be used in a third-party SDK library header file can be dynamically called when an APP runs, the workload of client integration is effectively reduced, and meanwhile, the size of a packet body of the APP is reduced.
Based on the content of the foregoing embodiment, before the dynamically invoking the second method in the class of the third-party application, the method further includes:
and determining that the third-party application is installed on the user terminal by dynamically calling a fourth method in the class of the third-party application.
It can be understood that, if the corresponding third-party application is not installed on the user terminal, the integration of the function of the third-party application cannot be realized, and therefore, before the second method in the class of the third-party application is dynamically called to send the authorization request, it is necessary to determine that the corresponding third-party application is installed on the user terminal.
Determining that the third-party application is installed on the user terminal by dynamically calling a fourth method in the class of the third-party application, specifically comprising:
dynamically generating the fourth method;
if the fourth method exists in the instantiation object of the class of the third-party application, finding and instantiating the fourth method;
and if the return value of the fourth method is a true value, determining that the third-party application is installed on the user terminal.
In one embodiment, a fourth method is dynamically generated by using a string acquisition selector function nsselectromstring, where the fourth method is used to determine whether a user terminal installs the third-party application, and a respondtoselection function is used to determine whether the fourth method exists in a method table pointed by a pointer of a class of the third-party application; if the fourth method exists in the method table pointed by the pointer of the class, finding the pointer corresponding to the fourth method in the method table pointed by the pointer of the class by using an obj c _ msgSend function, and instantiating the second method according to the pointer corresponding to the second method; and if the return value of the fourth method is a true value, determining that the third-party application is installed on the user terminal.
Taking the implementation of the WeChat authorized login function as an example, after the WeChat authorized login function is registered, the program returns to the target application program, the target application program calls a login page provided by the SDK, and after a user clicks a WeChat authorized login entry on the login page, NSSelectorFormString is used inside the SDK to generate an isWXAppInstalled, dynamic method SEL2, then a respondsToSelector function is used to judge whether a SEL2 method exists in a method table pointed by wxClass, if not, a failure termination step is returned, if so, a pointer corresponding to SEL2 is found in the method table pointed by objc _ msgSend to wxClass, and the method is instantiated according to the pointer; if the isWXApInstalled returns NO, the step is terminated if the user terminal is determined not to be provided with the WeChat, and if YES is returned, the step is entered into the next step if the user terminal is determined to be provided with the WeChat client. The above process can be implemented in pseudo code as follows:
Figure BDA0002389256620000101
Figure BDA0002389256620000111
based on the content of the foregoing embodiment, an authorization request is sent to the server of the third-party application by dynamically invoking the second method in the class of the third-party application, so that the server of the third-party application returns a parameter related to the function of the third-party application to the target application program, specifically:
dynamically generating the second method;
if the second method is determined to exist in the instantiation object of the class of the third-party application, the second method is found;
and taking the type of the parameter related to the function of the third-party application and the position returned by the parameter, which need to be acquired, as the input parameters of the second method, and instantiating the second method, so that the server of the third-party application returns the parameter related to the function of the third-party application to the target application program according to the type of the parameter and the position returned by the parameter.
Specifically, the SDK may dynamically generate a second method for sending an authorization request to the server of the third-party application by using a string acquisition selector function nsselectorformstarting, and determine whether the second method exists in a method table pointed by a class pointer of the third-party application by using a respondtosselector function; if it is determined that the second method exists in the instantiation object of the class of the third-party application, the second method can be found by using an objc _ msgSend assembly function, the type of the parameter related to the function of the third-party application and the position where the parameter is returned, which need to be acquired, are used as the input parameters of the second method, and the second method is instantiated, so that the server of the third-party application returns the parameter related to the function of the third-party application to the target application program according to the type of the parameter and the position where the parameter is returned.
In an optional embodiment, the step of taking the type of the parameter related to the function of the third-party application that needs to be acquired and the location where the parameter is returned as the entry parameter of the second method, instantiating the second method, so that the server of the third-party application returns the parameter related to the function of the third-party application to the target application program according to the type of the parameter and the location where the parameter is returned, specifically includes:
capturing an authorization request sending pointer in the target application program by using a character string construction class instance function, and if the authorization request sending pointer is captured, constructing an authorization request sending class object, wherein the authorization request sending class object is used for indicating the type of the parameter which needs to be acquired and is related to the function of the third-party application;
and taking the authorization request sending class object, the parameter returning position and the self parameter as the entry parameters of the second method, and instantiating the second method, so that the server of the third-party application returns the parameter related to the function of the third-party application to the target application program according to the authorization request sending class object, the parameter returning position and the self parameter.
Specifically, before instantiating the second method, an authorization request sending pointer in the target application program is captured by using a string construction class instance function NSClassFromString, and if the authorization request sending pointer is captured, an authorization request sending class object is constructed, wherein the authorization request sending class object is used for indicating the type of the parameter related to the function of the third-party application, which needs to be obtained,
in one embodiment, the authorization request send pointer is embodied as a SendAuthReq pointer. If the SendAuthReq pointer is captured, a SendAuthReq class object is constructed. The SendAuthReq class is used to indicate the specific type of parameters related to the functionality of the third party application that need to be obtained.
Then, the SendAuthReq class object, the location of parameter return, and the self parameter are used as the entry parameters of the second method, and the second method is instantiated, so that the server of the third-party application returns the parameter related to the function of the third-party application to the target application program according to the SendAuthReq class object, the location of parameter return, and the self parameter.
Taking the realization of the WeChat authorized login function as an example, the SDK internally uses NSSelectorFormString to generate a sendAuthReq, a viewController, a delete, a dynamic method SEL3, then uses a respondToSelector to judge whether a SEL3 method exists in a method table pointed by wxClass, if not, a failure termination step is returned, if so, an obj _ msgSend is used to find a pointer corresponding to the SEL3 method in the method table pointed by wxClass, and a SEL3 method is instantiated according to the pointer, wherein a NSClassFromString method is used to hosk a sendAuthReq pointer in an application, if the object cannot be instantiated, the sendAuthReq pointer does not exist, a failure is returned, and the termination step is terminated. Otherwise, constructing a SendAuthReq class object, transmitting the SendAuthReq class object, the object parameters of the login page and the self parameters into a SEL3 method, and jumping to the WeChat client side for authorized login. The above process can be implemented by the following codes:
Figure BDA0002389256620000131
based on the content of the above embodiment, by dynamically calling the third-party method in the class of the third-party application, the parameter related to the function of the third-party application, which is transmitted from the target application program, is called back, specifically:
dynamically generating the third method using a string acquisition selector function;
if the third method exists in the instantiation objects of the class of the third-party application, the third method is found, and the third method is instantiated by taking the parameters which are transmitted from the target application program and are related to the function of the third-party application as the input parameters of the third method.
Specifically, the third method may be dynamically generated by using a string acquisition selector function nsselectrsgursting, and the third method is configured to call back a parameter related to a function of the third-party application, which is imported from the target application program, and determine whether the third method exists in a method table pointed by a pointer of a class of the third-party application by using a respondtoselection function.
If the third method exists in the method table pointed by the pointer of the class, the objc _ msgSend assembly function can be used for searching and instantiating the third method, and the parameters which are imported from the target application program and are related to the functions of the third-party application are imported into the third method, so that parameter callback is realized.
Taking the implementation of the WeChat authorization login function as an example, after the WeChat authorization login is successful, the target application program APP jumps back, and responds to the application in the APPDELEEGATE. m file under the target application program APP with WeChat related parameters, namely openURL (Uniform resource locator) options, namely a callback function, and the target application program APP transmits the callback parameters into the SDK through an interface provided by the SDK. Detecting that a parameter is introduced into the SDK, continuously using NSSelectorFormSteng to generate a handleOpenURL, delete, a dynamic method SEL4, then using a respondToSector to judge whether a SEL4 method exists in a method table pointed by wxClass, if not, returning to a failure termination step, if so, using objc _ msgSend to find a pointer corresponding to the SEL4 method in the wxClass, instantiating the method, and then introducing a WeChat related parameter. The above process can be implemented using the following pseudo code:
Figure BDA0002389256620000141
based on the content of the above embodiment, after the step of calling back the parameters related to the function of the third-party application, the method further includes:
analyzing parameters related to the function of the third-party application by calling a callback function, and acquiring user data related to the function of the third-party application;
and uploading the user data to a uniform user center background to obtain corresponding user information and a user unique identifier, and returning the user information and the user unique identifier to the target application program.
Specifically, after parameters related to the function of the third-party application are acquired inside the SDK, a callback function is called, the parameters related to the function of the third-party application are analyzed, so that user data related to the function of the third-party application are acquired, then user information and a user unique identifier corresponding to the function of the third-party application are acquired in a background server according to the user data, and the user information and the user unique identifier are returned to the target application program for subsequent processing.
Still taking the implementation of the WeChat authorized login function as an example, the parameter related to the function of the third-party application is analyzed inside the SDK by calling the onResp, namely the callback function, of the file where the self parameter is located before, so as to obtain the accesToken and openID user authorization data corresponding to the WeChat authorized login function. And uploading the two parameters to a background of the unified user center to obtain corresponding user information and a user unique identifier inside the SDK, returning the data to the APP by the SDK, and displaying by the APP.
It should be noted that, in the above embodiments of the present invention, the nsclass fromstring function may be used to capture the pointer of the class of the third-party application, and the nsclass fromstring function may directly obtain a class from the character string, thereby implementing dynamic loading of the class; the method for dynamically generating the class of the third-party application by utilizing the NSSelectorFormString function can directly acquire a selector from a character string by utilizing the NSSelectorFromString function, thereby realizing the dynamic loading of the method; judging whether the dynamically generated method exists in the pointer of the class of the third-party application by using a respondToSelector function; and finding a dynamically generated pointer corresponding to the method in a method table pointed by a pointer of a class of a third-party application by using an objc _ msgSend assembly function to realize parameter transfer.
The processing method for integrating the third-party library provided by the embodiment of the invention realizes the combination of the dynamic call and the SDK full flow, realizes parameter transfer by using the obj c _ msgSend assembly function, and can effectively improve the code running efficiency of the dynamic integration third-party library.
As shown in fig. 2, a schematic flow chart of implementing a WeChat authorization login function by dynamically integrating a third party library according to an embodiment of the present invention is provided.
As shown in fig. 3, a schematic structural diagram of a processing apparatus integrated with a third party library according to an embodiment of the present invention includes:
a third-party application registration module 310, configured to invoke a first method for registering a third-party application in a class of the third-party application, where the third-party application is determined according to identification information transmitted by a target application program;
specifically, the third party application registration module 310 registers the third party application by invoking a first method in a class of the third party application. And the third-party application is determined according to the identification information transmitted by the target application program.
A dynamic authorization module 320, configured to send an authorization request to a server of the third-party application by dynamically calling a second method in the class of the third-party application, so that the server of the third-party application returns a parameter related to a function of the third-party application to the target application program;
specifically, the dynamic authorization module 320 sends an authorization request to the server of the third-party application by dynamically calling the second method in the class of the third-party application; after the authorization request is sent, jumping to a client of the third-party application, and after the user confirms authorization, returning parameters related to the function of the third-party application to the target application program by a server of the third-party application; the target application program transmits the parameters related to the functions of the third-party application into the SDK through a parameter transmission interface of the third-party application provided by the SDK.
The parameter callback module 330 is configured to callback parameters related to the functions of the third-party application, which are transmitted from the target application program, by dynamically calling a third-party method in the class of the third-party application.
Specifically, the parameter callback module 330 dynamically invokes a third method in the class of the third-party application, where the third method is used to callback the parameter that is imported from the target application and returned by the server of the third-party application. And obtaining the parameters returned by the server of the third-party application, and realizing the function authorization of the third-party application by using the parameters.
The processing device for integrating the third-party library provided by the embodiment of the invention solves the problem that the IOS-SDK can use the function of the third-party library only by introducing the header file through a dynamic calling mechanism, so that the IOS-SDK and the APP can use the function of the third-party library as required without depending on the existence of the third-party library during compiling, all the third-party libraries do not need to be introduced into a project, the workload of client integration is effectively reduced, and the size of the package of the APP is reduced.
Fig. 4 is a schematic entity structure diagram of an electronic device according to an embodiment of the present invention, and as shown in fig. 4, the electronic device may include: a processor (processor)410, a communication Interface 420, a memory (memory)430 and a communication bus 440, wherein the processor 410, the communication Interface 420 and the memory 430 are communicated with each other via the communication bus 440. The processor 410 may invoke a computer program stored on the memory 430 and operable on the processor 410 to perform the processing method of the integrated third party library provided by the above method embodiments, including, for example: dynamically calling a first method for registering a third-party application in a class of the third-party application in a Software Development Kit (SDK), wherein the third-party application is determined according to identification information transmitted by a target application program; sending an authorization request to a server of the third-party application by dynamically calling a second method in the class of the third-party application, so that the server of the third-party application returns parameters related to the function of the third-party application to the target application program; and calling back parameters which are transmitted from the target application program and are related to the functions of the third-party application by dynamically calling a third-party method in the class of the third-party application.
In addition, the logic instructions in the memory 430 may be implemented in the form of software functional units and stored in a computer readable storage medium when the software functional units are sold or used as independent products. Based on such understanding, the technical solutions of the embodiments of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the methods described in the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
An embodiment of the present invention further provides a non-transitory computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the processing method of the integrated third party library provided in the foregoing method embodiments, for example, the method includes: dynamically calling a first method for registering a third-party application in a class of the third-party application in a Software Development Kit (SDK), wherein the third-party application is determined according to identification information transmitted by a target application program; sending an authorization request to a server of the third-party application by dynamically calling a second method in the class of the third-party application, so that the server of the third-party application returns parameters related to the function of the third-party application to the target application program; and calling back parameters which are transmitted from the target application program and are related to the functions of the third-party application by dynamically calling a third-party method in the class of the third-party application.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (10)

1. A method for processing an integrated third party library, comprising:
dynamically calling a first method for registering a third-party application in a class of the third-party application in a Software Development Kit (SDK), wherein the third-party application is determined according to identification information transmitted by a target application program;
sending an authorization request to a server of the third-party application by dynamically calling a second method in the class of the third-party application, so that the server of the third-party application returns parameters related to the function of the third-party application to the target application program;
and calling back parameters which are transmitted from the target application program and are related to the functions of the third-party application by dynamically calling a third-party method in the class of the third-party application.
2. The processing method of the integrated third party library according to claim 1, wherein the software development kit SDK dynamically invokes a first method for registering the third party application in a class of third party applications, specifically:
dynamically generating the first method;
if the first method exists in the instantiation object of the class of the third-party application, the first method is found, and the first method is instantiated by taking the identification information as the entry parameter of the first method.
3. The processing method of claim 1, wherein before the dynamically invoking the second method in the class of the third-party application, the method further comprises:
and determining that the third-party application is installed on the user terminal by dynamically calling a fourth method in the class of the third-party application.
4. The processing method of the integrated third party library according to claim 1, wherein an authorization request is sent to the server of the third party application by dynamically calling a second method in the class of the third party application, so that the server of the third party application returns parameters related to the function of the third party application to the target application program, specifically:
dynamically generating the second method;
if the second method is determined to exist in the instantiation object of the class of the third-party application, the second method is found;
and taking the type of the parameter related to the function of the third-party application and the position returned by the parameter, which need to be acquired, as the input parameters of the second method, and instantiating the second method, so that the server of the third-party application returns the parameter related to the function of the third-party application to the target application program according to the type of the parameter and the position returned by the parameter.
5. The processing method for integrating the third-party library according to claim 4, wherein the second method is instantiated by taking the type of the parameter related to the function of the third-party application that needs to be acquired and the location where the parameter is returned as the entry of the second method, so that the server of the third-party application returns the parameter related to the function of the third-party application to the target application program according to the type of the parameter and the location where the parameter is returned, specifically:
capturing an authorization request sending pointer in the target application program by using a character string construction class instance function, and if the authorization request sending pointer is captured, constructing an authorization request sending class object, wherein the authorization request sending class object is used for indicating the type of the parameter which needs to be acquired and is related to the function of the third-party application;
and taking the authorization request sending class object, the parameter returning position and the self parameter as the entry parameters of the second method, and instantiating the second method, so that the server of the third-party application returns the parameter related to the function of the third-party application to the target application program according to the authorization request sending class object, the parameter returning position and the self parameter.
6. The processing method of claim 1, wherein the parameters related to the functions of the third-party application, which are transmitted from the target application program, are called back by dynamically calling a third-party method in the class of the third-party application, specifically:
dynamically generating the third method;
if the third method exists in the instantiation objects of the class of the third-party application, the third method is found, and the third method is instantiated by taking the parameters which are transmitted from the target application program and are related to the function of the third-party application as the input parameters of the third method.
7. The method for processing an integrated third party library as claimed in claim 1, wherein after the step of calling back the parameters related to the functions of the third party application, which are transmitted from the target application, the method further comprises:
analyzing parameters related to the function of the third-party application by calling a callback function, and acquiring user data related to the function of the third-party application;
and uploading the user data to a uniform user center background to obtain corresponding user information and a user unique identifier, and returning the user information and the user unique identifier to the target application program.
8. A processing device that integrates a third party library, comprising:
the third-party application registration module is used for calling a first method for registering the third-party application in a class of the third-party application, wherein the third-party application is determined according to identification information transmitted by a target application program;
the dynamic authorization module is used for sending an authorization request to a server of the third-party application by dynamically calling a second method in the class of the third-party application so as to enable the server of the third-party application to return parameters related to the function of the third-party application to the target application program;
and the parameter callback module is used for calling back the parameters which are transmitted from the target application program and are related to the functions of the third-party application by dynamically calling the third-party methods in the class of the third-party application.
9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the method of processing of an integrated third party library according to any one of claims 1 to 7 when executing the program.
10. A non-transitory computer readable storage medium, on which a computer program is stored, wherein the computer program, when executed by a processor, implements the steps of the processing method of the integrated third party library according to any one of claims 1 to 7.
CN202010108828.4A 2020-02-21 2020-02-21 Processing method and device for integrated third party library Active CN111309407B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010108828.4A CN111309407B (en) 2020-02-21 2020-02-21 Processing method and device for integrated third party library

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010108828.4A CN111309407B (en) 2020-02-21 2020-02-21 Processing method and device for integrated third party library

Publications (2)

Publication Number Publication Date
CN111309407A true CN111309407A (en) 2020-06-19
CN111309407B CN111309407B (en) 2023-07-11

Family

ID=71160160

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010108828.4A Active CN111309407B (en) 2020-02-21 2020-02-21 Processing method and device for integrated third party library

Country Status (1)

Country Link
CN (1) CN111309407B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112764729A (en) * 2021-01-08 2021-05-07 深圳依时货拉拉科技有限公司 Application software development method and device, computer equipment and readable storage medium
CN114461226A (en) * 2022-04-07 2022-05-10 广州易方信息科技股份有限公司 Method and device for solving mandatory dependence

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103530156A (en) * 2013-10-17 2014-01-22 北京奇虎科技有限公司 Method and device for dynamically loading and calling program
CN105094878A (en) * 2014-05-22 2015-11-25 阿里巴巴集团控股有限公司 System library file integration method and apparatus
WO2016061762A1 (en) * 2014-10-22 2016-04-28 刘大澎 Multi-channel sdk access system and method for mobile terminal software
CN105656922A (en) * 2016-02-04 2016-06-08 腾讯科技(深圳)有限公司 Login method and device of application program and intelligent equipment
CN105843654A (en) * 2016-04-14 2016-08-10 广州市久邦数码科技有限公司 Method and system for implementing dynamic loading of advertisement SDK (software development kit)
CN107977274A (en) * 2017-10-19 2018-05-01 北京奇艺世纪科技有限公司 The control method and device that SDK is called
US20180276053A1 (en) * 2017-03-23 2018-09-27 Airwatch Llc Dynamically integrating a client application with third-party services
CN108829467A (en) * 2018-04-28 2018-11-16 广东蜂助手网络技术股份有限公司 Third-party platform docks implementation method, device, equipment and storage medium
CN109522021A (en) * 2018-10-30 2019-03-26 咪咕文化科技有限公司 Parameter adjusts back processing method, device, electronic equipment and storage medium
CN109582400A (en) * 2018-11-30 2019-04-05 北京小米移动软件有限公司 Routine call method and device
CN110427319A (en) * 2019-07-22 2019-11-08 上海易点时空网络有限公司 The hot restorative procedure of lightweight and device, storage medium based on IOS

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103530156A (en) * 2013-10-17 2014-01-22 北京奇虎科技有限公司 Method and device for dynamically loading and calling program
CN105094878A (en) * 2014-05-22 2015-11-25 阿里巴巴集团控股有限公司 System library file integration method and apparatus
WO2016061762A1 (en) * 2014-10-22 2016-04-28 刘大澎 Multi-channel sdk access system and method for mobile terminal software
CN105656922A (en) * 2016-02-04 2016-06-08 腾讯科技(深圳)有限公司 Login method and device of application program and intelligent equipment
CN105843654A (en) * 2016-04-14 2016-08-10 广州市久邦数码科技有限公司 Method and system for implementing dynamic loading of advertisement SDK (software development kit)
US20180276053A1 (en) * 2017-03-23 2018-09-27 Airwatch Llc Dynamically integrating a client application with third-party services
CN107977274A (en) * 2017-10-19 2018-05-01 北京奇艺世纪科技有限公司 The control method and device that SDK is called
CN108829467A (en) * 2018-04-28 2018-11-16 广东蜂助手网络技术股份有限公司 Third-party platform docks implementation method, device, equipment and storage medium
CN109522021A (en) * 2018-10-30 2019-03-26 咪咕文化科技有限公司 Parameter adjusts back processing method, device, electronic equipment and storage medium
CN109582400A (en) * 2018-11-30 2019-04-05 北京小米移动软件有限公司 Routine call method and device
CN110427319A (en) * 2019-07-22 2019-11-08 上海易点时空网络有限公司 The hot restorative procedure of lightweight and device, storage medium based on IOS

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112764729A (en) * 2021-01-08 2021-05-07 深圳依时货拉拉科技有限公司 Application software development method and device, computer equipment and readable storage medium
CN112764729B (en) * 2021-01-08 2024-02-06 深圳依时货拉拉科技有限公司 Application software development method, device, computer equipment and readable storage medium
CN114461226A (en) * 2022-04-07 2022-05-10 广州易方信息科技股份有限公司 Method and device for solving mandatory dependence

Also Published As

Publication number Publication date
CN111309407B (en) 2023-07-11

Similar Documents

Publication Publication Date Title
CN107168960B (en) Service execution method and device
CN111143087B (en) Interface calling method, device, storage medium and server
EP3748500B1 (en) Inversion-of-control component service models for virtual environments
CN112948835A (en) Applet risk detection method and device
CN111309407B (en) Processing method and device for integrated third party library
CN107273226B (en) Method and device for integrating components in android system and calling integrated components
WO2022199292A1 (en) Detection of malicious behavior of applet
CN109522021B (en) Parameter callback processing method and device, electronic equipment and storage medium
CN109388388B (en) Information interaction method, device, equipment and storage medium between function modules
CN108595331B (en) Asynchronous interface testing method, medium, device and computing equipment
CN116561013B (en) Testing method and device based on target service framework, electronic equipment and medium
CN112732547B (en) Service testing method and device, storage medium and electronic equipment
CN111049795B (en) Method and device for detecting sensitive data unencrypted vulnerability of distributed Web application
CN110262912B (en) Calling method and device for procedure call gRPC
KR101684454B1 (en) Hybrid application and event handling method thereof
CN114301970A (en) Service calling method and device, electronic equipment and storage medium
CN113176907A (en) Interface data calling method and device, computer system and readable storage medium
CN111427630A (en) Cold start optimization method and device, electronic equipment and storage medium
CN112068814A (en) Method, device, system and medium for generating executable file
CN116010112B (en) Method and device for calling hook function, computer equipment and readable storage medium
CN114385384B (en) Application programming interface calling method and related equipment
CN109725887B (en) Data interaction method and device based on message research and development framework and terminal equipment
CN111125676B (en) Joint authorization method and device
CN113094608A (en) Content sharing method and device, electronic equipment and medium
CN116661894A (en) Native plug-in calling method, device, terminal equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant