Communication method and communication system
Obtaining mapping relationships through macro function declaration and reflection mechanisms, the problem of repetitive creation of communication channels and interface functions in cross-platform development frameworks is solved, and the maintainability and scalability of the code is improved.
Patent Information
- Application Number
- CN202510518717.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-23
- Publication Date
- 2025-08-08
AI Technical Summary
In the cross-platform development framework, the existing technology requires manual creation of communication channels and interface functions, resulting in increased duplication of code and longer R&D links, which are difficult to understand and expand.
The macro function declares the channel information and function information, uses the reflection mechanism to obtain the target channel and function, establish a mapping relationship between the interface and the channel class and functions, and simplifies the communication process between the cross-platform development framework side and the native platform side.
Reduces duplicate code, improves code maintainability and scalability, and simplifies the development process.
Smart Images

Figure CN120448154A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and more particularly, to a communication method and a communication system. Background Art
[0002] A cross-platform development framework allows developers to use a unified code base or language to develop applications that can run on multiple operating systems. In the process of development using a cross-platform development framework, due to the limitations of the cross-platform development framework, it may be necessary to establish a communication channel with the native platform side to call the native functions of the native platform side to achieve development needs. In order to achieve this goal, it is usually necessary to first create a communication channel class and interface function on the native platform side, and use the corresponding channel name and interface name to call it on the cross-platform development framework side. Each time a new channel and function requirement is added, this step needs to be repeated manually, generating additional duplicate code and increasing the workload of developers. One solution provided by the prior art is to complete the declaration of the communication channel by introducing a plug-in, creating a template code, and executing a script, but this will cause the R&D chain to become longer, making it difficult for technical personnel to understand the solution and expansion capabilities, and various template codes will increase the size of the application package, generating additional overhead. Summary of the Invention
[0003] In view of this, an embodiment of the present invention provides a communication method and a communication system to simplify the communication process between the cross-platform development framework side and the native platform side during the development process, reduce duplicate code, and improve the maintainability and scalability of the code.
[0004] In a first aspect, an embodiment of the present invention provides a communication method, applied to a native platform side, the method comprising:
[0005] Receive an interface call request sent by the cross-platform development framework side, wherein the interface call request includes an interface name;
[0006] Obtain a first mapping relationship and a second mapping relationship;
[0007] Determine a target channel according to the interface call request and the first mapping relationship, and obtain an object of the target channel based on a reflection mechanism;
[0008] Calling the target function in the object according to the interface call request and the second mapping relationship to complete the communication;
[0009] Among them, the first mapping relationship and the second mapping relationship are determined based on the following steps: declaring channel information and function information through macro functions; obtaining the interface declaration on the cross-platform development framework side; establishing a first mapping relationship between the interface and the channel class, and a second mapping relationship between the interface and the function based on the channel information, function information and the interface declaration.
[0010] Optionally, declaring channel information and function information through a macro function includes:
[0011] Declare channel information through a first macro function and register the channel information into a global channel list, wherein the channel information includes a channel name and a path where the channel is located;
[0012] Function information is declared in the channel class corresponding to each channel information through the second macro function and the function name, and the function corresponding to the function name is the native function of the native platform side.
[0013] Optionally, the function information is string information of the function corresponding to the function name, and establishing a first mapping relationship between the interface and the channel class, and a second mapping relationship between the interface and the function according to the channel information, the function information, and the interface declaration includes:
[0014] When the application on the cross-platform development framework side is started, collecting the channel information and the function information;
[0015] Based on the channel information, the function information and the interface declaration, a first mapping relationship between the interface and the channel class and a second mapping relationship between the interface and the string information are established.
[0016] Optionally, calling the target function in the object according to the interface call request and the second mapping relationship to complete the communication includes:
[0017] Determining, according to the interface name in the interface call request, character string information corresponding to the interface name from the second mapping relationship;
[0018] Obtain code segment information corresponding to the string information, and call a target function in the object according to the code segment information.
[0019] Optionally, declaring the function information in the channel class corresponding to each of the channel information by using the second macro function and the function name includes:
[0020] Obtain code segment information of the function corresponding to the function name;
[0021] The code segment information is converted into character string information and returned as the function information.
[0022] In a second aspect, an embodiment of the present invention provides a communication system, the system comprising:
[0023] The native platform side is used to execute the method as described in the first aspect of the embodiment of the present invention to complete communication with the cross-platform development framework side;
[0024] The cross-platform development framework side is used to send an interface call request to the native platform side.
[0025] Optionally, the cross-platform development framework side is further used to: complete an interface declaration, and send the interface declaration to the native platform side.
[0026] In a third aspect, an embodiment of the present invention provides an electronic device comprising a memory and a processor, wherein the memory is used to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method described in the first aspect of the embodiment of the present invention.
[0027] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect of the embodiment of the present invention is implemented.
[0028] In a fifth aspect, an embodiment of the present invention provides a computer program product, which, when executed on a computer, enables the computer to execute the method described in the first aspect of the embodiment of the present invention.
[0029] The embodiment of the present invention determines the target channel according to the interface call request and the first mapping relationship sent by the cross-platform development framework side, obtains the object of the target channel based on the reflection mechanism, and calls the target function in the object according to the interface call request and the second mapping relationship to complete the communication. In particular, the embodiment of the present invention declares channel information and function information through a macro function, obtains the interface declaration of the cross-platform development framework, establishes a first mapping relationship between the interface and the channel class, and a second mapping relationship between the interface and the function according to the channel information, function information and interface declaration. Therefore, the embodiment of the present invention can simplify the communication process between the cross-platform development framework side and the native platform side during the development process, and improves the maintainability and extensibility of the code. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] The above and other objects, features and advantages of the present invention will become more apparent through the following description of the embodiments of the present invention with reference to the accompanying drawings, in which:
[0031] Figure 1 is a schematic diagram of a communication system according to an embodiment of the present invention;
[0032] Figure 2 is a flow chart of a communication method according to an embodiment of the present invention;
[0033] Figure 3 is a flowchart of a method for determining a mapping relationship according to an embodiment of the present invention;
[0034] Figure 4is a flow chart of an interactive method of a communication system according to an embodiment of the present invention;
[0035] Figure 5 is a schematic diagram of a communication device according to an embodiment of the present invention;
[0036] Figure 6 is a schematic diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0037] The present application is described below based on the following embodiments, but the present application is not limited to these embodiments. In the detailed description of the present application below, certain specific details are described in detail. Those skilled in the art can fully understand the present application without the description of these details. To avoid obscuring the essence of the present application, well-known methods, processes, procedures, components, and circuits are not described in detail.
[0038] Furthermore, persons of ordinary skill in the art will appreciate that the figures provided herein are for illustration purposes only and are not necessarily drawn to scale.
[0039] Unless the context clearly requires otherwise, words like “include”, “comprising” and the like throughout this application should be interpreted as including rather than exclusive or exhaustive; that is, as meaning “including but not limited to”.
[0040] In the description of this application, it should be understood that the terms "first", "second", etc. are used for descriptive purposes only and should not be understood to indicate or imply relative importance. In addition, in the description of this application, unless otherwise specified, "plurality" means two or more.
[0041] A cross-platform development framework is a tool or framework that allows developers to create applications that run on multiple operating systems using a unified code base or language. By abstracting the differences between underlying operating systems, a cross-platform development framework provides a unified set of APIs (Application Programming Interfaces) and tools. This allows developers to write applications using a single code base and deploy them on multiple platforms, eliminating the traditional development process where developers need to write separate code for each operating system.
[0042] Although the cross-platform development framework provides some general APIs to access some basic functions, some specific hardware functions or system-level features still need to be implemented by calling the native functions of the native platform side (the operating system on which the current application is running). To this end, it is necessary to create a channel between the cross-platform development framework side and the native platform side, and then call the target function through the interface to complete the communication. The embodiment of the present invention provides a communication method and communication device to simplify the communication process, thereby improving development efficiency and enhancing the maintainability and scalability of the code.
[0043] Optionally, cross-platform development frameworks include Flutter, React Native, uniapp, etc. Depending on the cross-platform development framework, the native platform side may include iOS, Android, mini-programs, etc. This embodiment mainly uses Flutter as the cross-platform development framework side and iOS as the native platform side as an example for description.
[0044] Figure 1 FIG is a schematic diagram of a communication system according to an embodiment of the present invention. Figure 1 As shown, the communication system of the embodiment of the present invention includes a native platform side 11 and a cross-platform development framework side 12. During the communication process, the cross-platform development framework side 12 sends an interface call request to the native platform side 11. After receiving the interface call request, the native platform side 11 calls the target function corresponding to the interface call request to complete the relevant function and returns the processing result, completing one communication.
[0045] Figure 2 This is a flow chart of the communication method according to an embodiment of the present invention. After receiving the interface call request, the native platform side 11 executes the following Figure 2 The communication method shown in FIG. 1 realizes the target function corresponding to the calling interface call request. Figure 2 As shown, the communication method of the embodiment of the present invention includes the following steps:
[0046] Step S210: Receive an interface call request sent by the cross-platform development framework 12, wherein the interface call request includes an interface name. It should be understood that in Objective-C, an interface is actually a protocol. For ease of reading, the following text will use interface instead. Similarly, the following text will use function instead of method.
[0047] Step S220: Acquire a first mapping relationship and a second mapping relationship, wherein the first mapping relationship is used to represent the correspondence between the interface and the channel class, and the second mapping relationship is used to represent the correspondence between the interface and the function information.
[0048] Figure 3 FIG. 1 is a flow chart of a method for determining a mapping relationship according to an embodiment of the present invention. Figure 3As shown, in an optional implementation, the first mapping relationship and the second mapping relationship can be determined based on the following steps:
[0049] Step S310: Declare channel information and function information through a macro function. A channel is a bridge mechanism used to transfer data and call functions between different environments or modules.
[0050] Optionally, channel information and function information are declared through macro functions, which can specifically include: declaring channel information through a first macro function and registering the channel information in the global channel list, and declaring function information in the channel class corresponding to each channel information through a second macro function and function name. Among them, the channel information includes the channel name and the path where the channel is located. The function corresponding to the function name is the native function on the native platform side. Therefore, the specific implementation process of the function can be determined by the function name. The global channel list is a container for centrally managing all channels. It manages these channels in a unified manner with a certain data structure (such as an array, dictionary, etc.) to facilitate the creation, search and call of channels.
[0051] In the Objective-C language used by the iOS platform, macro functions are code snippets defined by the preprocessing directive #define and are used to replace text in the code before compilation. This embodiment predefines the first and second macro functions described above in the code to complete the specific implementation process of declaring channel information and function information. As a result, developers do not need to write a lot of repetitive code each time when registering channels and functions. They can call complex functions with just two simple lines of code, for example:
[0052] FLUTTER_EXPORT_CHANNEL(@"com.example.channel / device")
[0053] FLUTTER_EXPORT_METHOD(getChannel:(id)arguments result;(FlutterResult)result){
[0054] Result(@"AppStore");
[0055] }
[0056] The FLUTTER_EXPORT_CHANNEL macro function is the first macro function, which declares channel information with the name device and the path com.example.channel, and registers this channel information in the global channel list. The FLUTTER_EXPORT_METHOD macro function is the second macro function, which declares the corresponding function information in the device channel registered by the first macro function. After registration, the Flutter client can receive communication by calling the getChannel function and obtain the "AppStore" string (that is, the function information).
[0057] In an optional implementation, the function information is the string information of the function corresponding to the function name. Declaring the function information in the channel class corresponding to each channel information through the second macro function and the function name may include: obtaining the code segment information of the function corresponding to the function name, converting the code segment information into string information, and returning it as the function information. Its specific implementation process can be based on the function method_getImplementation in the runtime system of Objective-C. This function can return a pointer to the corresponding function (i.e., the code segment information of the corresponding function) based on the input parameters (an object of the Method type, representing a function, including function name, parameter type, return value type, etc.). The implementation of the function can be directly called through the pointer. After obtaining the code segment information of the corresponding function, it is processed twice to convert the code segment information into string information to facilitate data transmission during the communication process.
[0058] It should be understood that the above process of declaring channel information and function information can occur before the program runs, that is, pre-registered and collected when the program is started later, or it can be dynamically registered and collected while the program is running. Through the latter, this embodiment can easily complete the addition of channels with two lines of code.
[0059] This embodiment uses macro functions to declare channel and function information, allowing new channels and functions to be added with just two lines of code, effectively reducing the amount of code required for the registration process. This solves the pain point of requiring repetitive code each time a new channel is added, facilitating code understanding for technical personnel, improving code maintainability and scalability, and enhancing application development efficiency.
[0060] Step S320: Obtain the interface declaration of the cross-platform development framework. The interface declaration is used to specify the interface name, parameter type, and function that each interface should have during the communication process.
[0061] Correspondingly, the cross-platform development framework side 12 is also used to complete the interface declaration and send the interface declaration to the native platform side 11.
[0062] Step S330: establishing a first mapping relationship between the interface and the channel class, and a second mapping relationship between the interface and the function according to the channel information, the function information and the interface declaration.
[0063] In an optional implementation, step S330 may specifically include: when the application on the cross-platform development framework side 12 is started, collecting the channel information and function information declared in step S310, and establishing a first mapping relationship between the interface and the channel class, and a second mapping relationship between the interface and the string information based on the channel information, function information and interface declaration. Optionally, the first mapping relationship and the second mapping relationship can be implemented through storage structures such as dictionaries, hash tables or mapping tables. Optionally, the above-mentioned process of collecting channel information and function information can also be performed immediately when the channel and function are registered, or when predetermined conditions are met, such as when the user clicks a button and triggers the relevant logic.
[0064] Step S230: Determine the target channel based on the interface call request and the first mapping relationship, and obtain the target channel object based on the reflection mechanism. In the Objective-C language, the reflection mechanism is a capability provided by the runtime system that allows programs to dynamically create class objects based on the class name, call object methods based on the method name, and dynamically obtain class information at runtime. Specifically, step S230 may include: obtaining the interface name in the interface call request, determining the target channel corresponding to the interface name based on the first mapping relationship, and dynamically creating the target channel class object based on the target channel name based on the reflection mechanism.
[0065] In step S240, the target function in the object is called based on the interface call request and the second mapping relationship to complete the communication. After calling the target function, the native platform side 11 obtains the corresponding processing result and sends the processing result to the cross-platform development framework side 12. The processing result includes at least the execution status of the interface call request, which indicates whether the communication was successful. If the target function has a return value, the processing result also includes the return value of the target function.
[0066] In an optional implementation, step S240 may specifically include: determining, based on the interface name in the interface call request, the string information corresponding to the interface name from the second mapping relationship, obtaining the code segment information corresponding to the string information, and calling the target function in the object based on the code segment information. The specific execution process is as follows:
[0067] SEL selector=NSSelectorFromString(methodSign);
[0068] if([self respondsToSelector:selector]){
[0069] [self performSelector:selector withObject:call.arguments withObject:result];
[0070] }
[0071] NSSelectorFromString is a runtime function that converts a string into a SEL selector, which represents the name of a function. The respondsToSelector function checks whether an object can respond to the method represented by a specified selector. By checking whether an object supports a function before calling it, you can avoid program crashes caused by calling a nonexistent function. The performSelector function allows you to dynamically call an object's method based on a selector at runtime.
[0072] Through the above code, the program can convert the acquired string information into executable code and execute it, thereby realizing the call of the target function and completing the reduction of the steps to start communication. Compared with the existing technology of first registering the communication channel and interface function on the native platform side, then calling the channel using the channel name and channel path on the cross-platform development framework side, and forwarding the call request to the interface function on the native platform side, this embodiment can directly obtain the function information and execute it according to the interface name. There is no step of determining the channel and forwarding the request, and there is no need to rely on external capabilities. It is completed entirely by relying on the characteristics of the language itself. Without adding new application packages, it effectively simplifies the communication process between the cross-platform development framework side and the native platform side during the development process.
[0073] This embodiment determines the target channel according to the interface call request and the first mapping relationship sent by the cross-platform development framework side, obtains the object of the target channel based on the reflection mechanism, and calls the target function in the object according to the interface call request and the second mapping relationship to complete the communication. Among them, the embodiment of the present invention declares channel information and function information through a macro function, obtains the interface declaration of the cross-platform development framework, establishes a first mapping relationship between the interface and the channel class, and a second mapping relationship between the interface and the function according to the channel information, function information and interface declaration. Therefore, the embodiment of the present invention can simplify the communication process between the cross-platform development framework side and the native platform side during the development process, and improves the maintainability and extensibility of the code.
[0074] Figure 4 FIG. 1 is a flow chart of an interactive method of a communication system according to an embodiment of the present invention. Figure 4 As shown, in an optional implementation, the interaction method of the communication system specifically includes the following steps:
[0075] In step S410 , the cross-platform development framework 12 completes the interface declaration.
[0076] In step S420 , the native platform side 11 declares channel information and function information through a macro function.
[0077] Step S430 : The cross-platform development framework side 12 sends an interface declaration to the native platform side 11 .
[0078] In step S440 , the native platform side 11 establishes a first mapping relationship between the interface and the channel class, and a second mapping relationship between the interface and the function according to the channel information, the function information, and the interface declaration.
[0079] Step S450 : The cross-platform development framework side 12 sends an interface call request to the native platform side 11 .
[0080] In step S460 , the native platform side 11 determines the target channel according to the interface call request and the first mapping relationship, and obtains the object of the target channel based on the reflection mechanism.
[0081] Step S470: Call the target function in the object according to the interface call request and the second mapping relationship to obtain a processing result.
[0082] In step S480 , the native platform side 11 sends the processing result to the cross-platform development framework side 12 .
[0083] Those skilled in the art will understand that in the above-mentioned method of the specific implementation method, the writing order of each step does not mean a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.
[0084] This embodiment determines the target channel according to the interface call request and the first mapping relationship sent by the cross-platform development framework side, obtains the object of the target channel based on the reflection mechanism, and calls the target function in the object according to the interface call request and the second mapping relationship to complete the communication. In this embodiment, the channel information and function information are declared through a macro function, the interface declaration of the cross-platform development framework is obtained, and the first mapping relationship between the interface and the channel class and the second mapping relationship between the interface and the function are established according to the channel information, function information and interface declaration. Therefore, the embodiment of the present invention can simplify the communication process between the cross-platform development framework side and the native platform side during the development process, thereby improving the maintainability and extensibility of the code.
[0085] Figure 5Schematic diagram of a communication device according to an embodiment of the present invention. Further, an embodiment of the present invention also provides a communication device for deployment on a native platform side, such as Figure 5 As shown, the communication device at least includes a receiving unit 51, a mapping acquisition unit 52, a first processing unit 53 and a second processing unit 54.
[0086] The receiving unit 51 is configured to receive an interface calling request sent by the cross-platform development framework side, where the interface calling request includes an interface name.
[0087] The mapping acquisition unit 52 is configured to acquire a first mapping relationship and a second mapping relationship.
[0088] In an optional implementation, the first mapping relationship and the second mapping relationship are determined by the mapping acquisition unit 52 performing the following steps: declaring channel information and function information through a macro function, obtaining the interface declaration on the cross-platform development framework side, and establishing a first mapping relationship between the interface and the channel class, as well as a second mapping relationship between the interface and the function based on the channel information, function information and interface declaration.
[0089] Optionally, the mapping acquisition unit 52 includes a first registration subunit and a second registration subunit. The first registration subunit is configured to declare channel information through a first macro function and register the channel information in a global channel list. The second registration subunit is configured to declare function information in a channel class corresponding to each channel information through a second macro function and a function name, where the function corresponding to the function name is a native function on the native platform side.
[0090] Optionally, the function information is the string information of the function corresponding to the function name, and the second mapping relationship between the interface and the function is the second mapping relationship between the interface and the string information. Establishing the first mapping relationship between the interface and the channel class and the second mapping relationship between the interface and the function based on the channel information, function information and interface declaration includes: when the application on the cross-platform development framework side is started, collecting channel information and function information, and establishing the first mapping relationship between the interface and the channel class and the second mapping relationship between the interface and the string information based on the channel information and function information.
[0091] In an optional implementation, the second registration subunit is specifically configured to obtain code segment information of a function corresponding to the function name, convert the code segment information into string information, and return it as function information.
[0092] The first processing unit 53 is configured to determine a target channel according to the interface call request and the first mapping relationship, and obtain an object of the target channel based on a reflection mechanism.
[0093] The second processing unit 54 is configured to call the target function in the object according to the interface call request and the second mapping relationship to complete the communication.
[0094] In an optional implementation, the second processing unit 54 is specifically configured to: determine the string information corresponding to the interface name from the second mapping relationship according to the interface name in the interface call request, obtain the code segment information corresponding to the string information, and call the target function in the object according to the code segment information.
[0095] This embodiment determines the target channel according to the interface call request and the first mapping relationship sent by the cross-platform development framework side, obtains the object of the target channel based on the reflection mechanism, and calls the target function in the object according to the interface call request and the second mapping relationship to complete the communication. Among them, the embodiment of the present invention declares channel information and function information through a macro function, obtains the interface declaration of the cross-platform development framework, establishes a first mapping relationship between the interface and the channel class, and a second mapping relationship between the interface and the function according to the channel information, function information and interface declaration. Therefore, the embodiment of the present invention can simplify the communication process between the cross-platform development framework side and the native platform side during the development process, and improves the maintainability and extensibility of the code.
[0096] Figure 6 Schematic diagram of an electronic device according to an embodiment of the present invention. The electronic device may be deployed with an operating system of a native platform, and is used to receive an interface call request sent by a cross-platform development framework and communicate. Figure 6 As shown, Figure 6 The electronic device shown includes a general computer hardware structure, which includes at least a processor 61 and a memory 62. The processor 61 and the memory 62 are connected via a bus 63. The memory 62 is suitable for storing instructions or programs executable by the processor 61. The processor 61 can be an independent microprocessor or a collection of one or more microprocessors. Thus, the processor 61 executes the instructions stored in the memory 62, thereby executing the method flow of the embodiment of the present invention as described above to process data and control other devices. The bus 63 connects the above-mentioned multiple components together, and at the same time connects the above-mentioned components to the display controller 64 and the display device and the input / output (I / O) device 65. The input / output (I / O) device 65 can be a mouse, keyboard, modem, network interface, touch input device, somatosensory input device, printer, and other devices known in the art. Typically, the input / output device 65 is connected to the system via an input / output (I / O) controller 66.
[0097] It will be understood by those skilled in the art that the embodiments of the present application may be provided as methods, devices (equipment), or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-readable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0098] The present application is described with reference to flowcharts of methods, apparatuses (devices), and computer program products according to embodiments of the present application. It should be understood that each process in the flowcharts can be implemented by computer program instructions.
[0099] These computer program instructions may be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device that implements the process Figure 1 A function specified in a process or multiple processes.
[0100] These computer program instructions can also be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce the instructions for implementing the process Figure 1 A device that specifies functions in a process or multiple processes.
[0101] Another embodiment of the present invention relates to a non-volatile storage medium for storing a computer-readable program, wherein the computer-readable program is used to enable a computer to execute part or all of the above method embodiments.
[0102] That is, those skilled in the art will understand that all or part of the steps in the above-mentioned embodiments can be implemented by specifying relevant hardware through a program, which is stored in a storage medium and includes a number of instructions for causing a device (which may be a single-chip microcomputer, chip, etc.) or a processor to execute all or part of the steps of the methods described in the embodiments of the present application. The aforementioned storage medium includes: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc., various media that can store program code.
[0103] The foregoing is merely a preferred embodiment of the present application and is not intended to limit the present application. Persons skilled in the art will readily appreciate that various modifications and variations are possible. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present application are intended to be within the scope of protection of the present application.
Claims
1. A communication method, applied to the native platform side, characterized in that: The method comprises: Receive an interface call request sent by the cross-platform development framework side, wherein the interface call request includes an interface name; Obtain a first mapping relationship and a second mapping relationship; Determine a target channel according to the interface call request and the first mapping relationship, and obtain an object of the target channel based on a reflection mechanism; Calling the target function in the object according to the interface call request and the second mapping relationship to complete the communication; Among them, the first mapping relationship and the second mapping relationship are determined based on the following steps: declaring channel information and function information through macro functions; obtaining the interface declaration on the cross-platform development framework side; establishing a first mapping relationship between the interface and the channel class, and a second mapping relationship between the interface and the function based on the channel information, function information and the interface declaration.
2. The method according to claim 1, characterized in that The declaration of channel information and function information through macro functions includes: Declare channel information through a first macro function and register the channel information into a global channel list, wherein the channel information includes a channel name and a path where the channel is located; Function information is declared in the channel class corresponding to each channel information through the second macro function and the function name, and the function corresponding to the function name is the native function of the native platform side.
3. The method according to claim 2, characterized in that The function information is string information of the function corresponding to the function name. The establishing of a first mapping relationship between the interface and the channel class, and a second mapping relationship between the interface and the function according to the channel information, the function information and the interface declaration includes: When the application on the cross-platform development framework side is started, collecting the channel information and the function information; Based on the channel information, the function information and the interface declaration, a first mapping relationship between the interface and the channel class and a second mapping relationship between the interface and the string information are established.
4. The method according to claim 3, characterized in that Calling the target function in the object according to the interface call request and the second mapping relationship to complete the communication includes: Determining, according to the interface name in the interface call request, character string information corresponding to the interface name from the second mapping relationship; Obtain code segment information corresponding to the string information, and call a target function in the object according to the code segment information.
5. The method according to claim 2, characterized in that Declaring the function information in the channel class corresponding to each of the channel information by using the second macro function and the function name includes: Obtain code segment information of the function corresponding to the function name; The code segment information is converted into character string information and returned as the function information.
6. A communication system, characterized in that: The system comprises: The native platform side is used to execute the method according to any one of claims 1 to 5 to complete the communication with the cross-platform development framework side; The cross-platform development framework side is used to send an interface call request to the native platform side.
7. The system according to claim 6, characterized in that The cross-platform development framework side is further used to complete the interface declaration and send the interface declaration to the native platform side.
8. An electronic device comprising a memory and a processor, characterized in that: The memory is configured to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method according to any one of claims 1 to 5.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
10. A computer program product, characterized in that When the computer program product is run on a computer, the computer is caused to perform the method according to any one of claims 1 to 5.