Function module calling method, device, electronic device and readable storage medium
By creating and binding functional modules in the IOS system, the coupling problem between functional modules is solved, faster module calls are achieved and maintenance difficulty is reduced.
Patent Information
- Application Number
- CN202010875817.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-08-27
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2040-08-27
AI Technical Summary
In the prior art, the mutual reference between functional modules leads to serious coupling problems, resulting in code merging conflicts and maintenance difficulties.
By creating a protocol for target function modules in the IOS system, it is stored in a preset dictionary, and registered in a preset array, traversing and binding the target function modules and protocols, creating a call interface, and realizing the call to the target function module.
It effectively eliminates the coupling problem between functional modules, reduces the workload of maintenance and updates, and realizes faster function module calls.
Smart Images

Figure CN114116242B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a function module calling method, device, electronic device and readable storage medium. Background Art
[0002] Currently, calls between functions and classes are accomplished through mutual references between functions. For example, file A references file B, file B references file C, file C references file D, file A references file D, file D references file B, and so on. Each reference relationship is an inclusion relationship, which leads to the inclusion of different files, resulting in severe coupling, which can easily lead to subsequent code merge conflicts and difficult maintenance. Summary of the Invention
[0003] The embodiments of the present invention provide a method, device, electronic device and readable storage medium for calling a function module, which can effectively eliminate the coupling problem caused by mutual calling between function modules.
[0004] In a first aspect, an embodiment of the present invention provides a method for calling a function module, which is applied to calling a function module in an IOS system. The method includes:
[0005] In response to a trigger operation of loading a preset page, each target functional module and its corresponding target protocol included in the preset page are associated and stored in a preset dictionary, and the corresponding relationship between each target functional module and the target protocol is registered in a preset array, wherein the target protocol is pre-created for the target functional module and defines the functional functions included in the target functional module;
[0006] In response to a trigger operation of starting the application to which the preset page belongs, the preset array is traversed, and for each target functional module traversed, the following creation and binding steps are performed:
[0007] Detecting whether the name of the target functional module and the corresponding target protocol meet a preset configuration condition, and if so, obtaining the target functional module from the preset dictionary;
[0008] Binding the acquired target functional module to the corresponding target protocol by calling a preset module binding function, including: determining whether the target functional module complies with the target protocol through a conformsToProtocol function; if so, establishing a synchronization lock; searching for the target functional module to be bound through the target protocol; encapsulating the found target functional module into an object; and reassigning the object to the target protocol in the preset dictionary;
[0009] A calling interface is created, where the calling interface is used to call a target function module in the preset dictionary that is bound to the target protocol through the target protocol.
[0010] Furthermore, after creating the calling interface, the following steps are also included:
[0011] Obtain the protocol name, target function pointer selector, and target function corresponding to the target function, wherein the target function is a function function that needs to be called, and the target function pointer is used to determine whether the target function can be called;
[0012] The target function is called by passing the protocol name, target function pointer selector and target function into the calling interface.
[0013] Furthermore, calling the target function by passing the protocol name, the target function pointer selector, and the target function into the calling interface includes:
[0014] Generate a protocol by passing in the protocol name;
[0015] Obtain the client management object through defaultCenter. The client management object is a service object that complies with the protocol.
[0016] Through the respondsToSelector method, it is determined whether the service complies with the selector method. If so, the target function is called through the service. If not, the service is set to empty.
[0017] Furthermore, the detecting whether the name of the target functional module and the corresponding protocol meets a preset configuration condition includes:
[0018] Obtain the target functional module and the protocol name of the corresponding target protocol, and detect whether the protocol name and the target functional module both exist;
[0019] If it exists, the conformsToProtocol protocol method is used to detect whether the target functional module complies with the preset module loading protocol. If it does, it is determined that the name of the target functional module and the corresponding protocol meet the preset configuration conditions, wherein the module loading protocol is used to initialize the target functional module.
[0020] Furthermore, searching for a target functional module to be bound through the target protocol includes:
[0021] Get the string name of the target protocol as the key value through the NSStringFromProtocol method;
[0022] Search the corresponding client by the key value in the preset dictionary, determine whether the type of the client is correct, and if so, obtain the object of the client, wherein the object of the client is the corresponding target functional module, the client is a further encapsulation of the target functional module, and the client object contains the attributes of the target functional module;
[0023] If the client object does not exist, the target protocol is converted into a string type key, and a client object is created, and the parameters of the target function module are passed into the client object.
[0024] Furthermore, the target function module is a box or a function for realizing the target function.
[0025] In a second aspect, an embodiment of the present invention provides a function module calling device, the device comprising:
[0026] a registration module, configured to, in response to a triggering operation of loading a preset page, associate and store each target functional module and its corresponding target protocol contained in the preset page in a preset dictionary, and register the corresponding relationship between each target functional module and target protocol in a preset array, wherein the target protocol is pre-created for the target functional module and defines the functional functions contained in the target functional module;
[0027] The binding module is configured to, in response to a triggering operation of starting the application to which the preset page belongs, traverse the preset array and, for each target functional module traversed, perform the following creation and binding steps:
[0028] Detecting whether the name of the target functional module and the corresponding target protocol meet a preset configuration condition, and if so, obtaining the target functional module from the preset dictionary;
[0029] Binding the acquired target functional module to the corresponding target protocol by calling a preset module binding function, including: determining whether the target functional module complies with the target protocol through a conformsToProtocol function; if so, establishing a synchronization lock; searching for the target functional module to be bound through the target protocol; encapsulating the found target functional module into an object; and reassigning the object to the target protocol in the preset dictionary;
[0030] The interface creation module is used to create a calling interface, wherein the calling interface is used to call the target function module bound to the target protocol in the preset dictionary through the target protocol.
[0031] Furthermore, the function module calling device further includes:
[0032] A parameter acquisition module is used to obtain the protocol name corresponding to the target function, the target function pointer selector, and the target function, wherein the target function is a function function that needs to be called, and the target function pointer is used to determine whether the target function can be called;
[0033] The calling module is used to call the target function by passing the protocol name, target function pointer selector and target function into the calling interface.
[0034] In a third aspect, an embodiment of the present invention further provides an electronic device comprising a processor and a memory, wherein the memory is coupled to the processor and stores instructions, which, when executed by the processor, enable the electronic device to execute the steps of the function module calling method provided in the first aspect above.
[0035] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the steps of the function module calling method provided in the first aspect are implemented.
[0036] The technical solutions provided in the embodiments of the present invention have at least the following technical effects or advantages:
[0037] The function module calling method and device provided by the embodiments of the present invention create a protocol for the target function module to be called in a preset page. The protocol defines the function functions contained in the target function module. The target function module and the corresponding target protocol are then stored in a preset dictionary. The correspondence between each target function module and the target protocol is registered in a preset array. The preset array is then traversed to create each target function module and bind each target function module to the corresponding target protocol. This creates a calling interface for calling the target function module bound to the target protocol via the target protocol. Compared to the prior art, creating a protocol for the target function module to be called and calling the target function module according to the protocol and the created calling interface makes calling the target function module more convenient and quick. Furthermore, calling between function modules does not require mutual references, effectively eliminating the coupling problem caused by mutual references between function modules, reducing the dependencies between function modules, and significantly reducing the workload of maintaining and updating these function modules.
[0038] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are specifically listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Various other advantages and benefits will become apparent to those skilled in the art upon reading the detailed description of the preferred embodiment below. The accompanying drawings are for illustration purposes only and are not to be considered as limiting the present invention. The same reference symbols are used throughout the drawings to represent the same components. In the drawings:
[0040] Figure 1 A flowchart of a function module calling method provided by the first embodiment of the present invention is shown;
[0041] Figure 2 A flowchart showing the steps of creating and binding provided by the first embodiment of the present invention is shown;
[0042] Figure 3 A functional module block diagram of a functional module calling device provided by a second embodiment of the present invention is shown;
[0043] Figure 4 A schematic structural diagram of an electronic device provided by a third embodiment of the present invention is shown. DETAILED DESCRIPTION
[0044] The embodiment of the present invention provides a method, device, electronic device and readable storage medium for calling a function module, which can effectively eliminate the coupling problem caused by mutual calling between functions. The method is applied to calling a function module in an IOS system, including: in response to a trigger operation of loading a preset page, each target function module contained in the preset page and the corresponding target protocol are associated and stored in a preset dictionary, and the corresponding relationship between each target function module and the target protocol is registered in a preset array, wherein the target protocol is created in advance for the target function module, and the target protocol defines the function functions contained in the target function module; in response to a trigger operation of starting the application to which the preset page belongs, the preset array is traversed, and for each target function module traversed, the following creation and binding steps are performed: detecting whether the name of the target function module and the corresponding target protocol are The preset configuration conditions are met. If so, the target function module is obtained from the preset dictionary; the obtained target function module is bound to the corresponding target protocol by calling the preset module binding function, including: judging whether the target function module complies with the target protocol through the conformsToProtocol function, and if so, establishing a synchronization lock, searching for the target function module to be bound through the target protocol, encapsulating the found target function module into an object, and reassigning the object to the target protocol in the preset dictionary; after completing the creation and binding steps, creating a calling interface, the calling interface is used to call the target function module bound to the target protocol through the target protocol.
[0045] It should be noted that, in the embodiment of the present invention, the preset page can be determined according to the actual application scenario. For example, the preset page can be a live broadcast room, and accordingly, the application to which the preset page belongs can be a live broadcast application; or, the preset page can be a chat interface of an instant messaging application, and accordingly, the application to which the preset page belongs can be an instant messaging application, and so on. The target function module is a function module that needs to be called, that is, a program module used to implement a certain function. For example, the target function module can be a box, or a function used to implement a target function such as registering an account, sending voice or sending pictures. Among them, box refers to the management class corresponding to each function. For example, in the chat interface of an instant messaging application, the input box can be regarded as a box, and the program modules that implement functions such as sending voice, sending pictures, and sending red envelopes can also be regarded as boxes respectively.
[0046] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. The components of the embodiments of the present invention generally described and shown in the drawings herein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present invention.
[0047] In this document, the term "and / or" simply describes a relationship between related objects, indicating that three possible relationships exist. For example, "A and / or B" can represent: A exists alone, A and B exist simultaneously, or B exists alone. Additionally, the character " / " in this document generally indicates that the related objects are in an "or" relationship.
[0048] The first embodiment of the present invention provides a method for calling a function module, which is applied to calling a function module in an IOS system. It should be noted that, for ease of understanding, the embodiment of the present invention mainly takes the function module box as an example to illustrate the process of calling the box through this solution. In other embodiments of the present invention, it can also be applied to calls between other function modules. Figure 1 As shown, the method may include the following steps S101 to S103.
[0049] Step S101 , in response to a trigger operation of loading a preset page, each target box included in the preset page and its corresponding target protocol are associated and stored in a preset dictionary, and the corresponding relationship between each target box and target protocol is registered in a preset array.
[0050] In this embodiment, the target box is the box that needs to be called in the preset page. For example, the preset page contains boxes A, B, C, and D. Box A needs to call box B, box B needs to call box C, and box C needs to call box D. In this case, boxes B, C, and D are all used as target boxes.
[0051] The target protocol is created in advance for the target box. For each target box, a target protocol is created. The target protocol defines the functional functions contained in the corresponding target box.
[0052] That is to say, before executing step S101, in order to realize the call between boxes, you need to execute the protocol creation step first. Write a protocol for each target box. This protocol is a separate file. This protocol file needs to comply with <nsobject>Protocol, and this protocol needs to include #import<Foundation / Foundation.h> In addition, the protocol needs to be defined, because the function needs to be defined before the function call. Some functional functions can be defined in this protocol. These things are a separate protocol.
[0053] After defining the protocol, you need to conform to the target protocol in each target box. This requires importing the protocol defined in the protocol creation step and using the conform method to conform to the protocol. In other words, you need to bind the protocol to the box. This binding occurs automatically when the box is created, and the binding method is to conform to the protocol created for that box.
[0054] In conventional solutions, boxes don't need to conform to protocols, nor do they need to create them; they can only reference each other. This solution adds a protocol that contains the parts that need to be called by each other. This extracts the functions that need to be called by each other through the protocol, extracting the function declarations and defining them in the protocol. This effectively facilitates calling between boxes and eliminates the code coupling problem caused by mutual references.
[0055] After creating a corresponding target protocol for each target box in a preset page, all boxes are registered when loading a preset page, such as a live studio. The target boxes and corresponding target protocols to be called in the loaded preset page are stored in a preset dictionary. The key of each dictionary is the protocol that the target box complies with, and the value of each dictionary is the target box. The correspondence between each target box and target protocol is then registered in a preset array. After this, the protocol binding for these target boxes can be performed in step S102.
[0056] Step S102 , in response to a triggering operation of starting the application to which the preset page belongs, the preset array is traversed, and for each target box traversed, creation and binding steps are performed.
[0057] like Figure 2 As shown, the creation and binding steps may include the following steps S201 and S202. This process adopts a static binding method, which is conducive to improving the binding efficiency between the box and the protocol and saving memory.
[0058] Step S201 : Detect whether the name of the target box and the corresponding target protocol meet the preset configuration conditions. If so, obtain the target box from the preset dictionary.
[0059] Specifically, the process of detecting whether the target box and the name of the corresponding target protocol meet the preset configuration conditions may include: obtaining the target box and the protocol name of the corresponding target protocol, detecting whether the protocol name and the target box both exist; if so, detecting whether the target box complies with the preset module loading protocol through the conformsToProtocol protocol method, and if so, determining that the target box and the name of the corresponding protocol meet the preset configuration conditions, wherein the module loading protocol is used to initialize the target box.
[0060] Step S202 binds the acquired target box to the corresponding target protocol by calling a preset module binding function, including: determining whether the target box complies with the target protocol through the conformsToProtocol function; if so, establishing a synchronization lock; searching for the target box to be bound through the target protocol; encapsulating the found target box into an object; and reassigning the object to the target protocol in the preset dictionary.
[0061] In the above step S202, the process of searching for the target box to be bound through the target protocol may include: obtaining the string name of the target protocol through the NSStringFromProtocol method as the key value; searching the corresponding client through the key value in the preset dictionary to determine whether the client type is correct; if correct, obtaining the client object, wherein the client object is the corresponding target box, the client is a further encapsulation of the target box, and the client object contains the properties of the target box; if the client object does not exist, converting the target protocol into a string type key, creating a client object, and passing the parameters of the target box into the client object.
[0062] In the specific implementation process, each time the application to which the preset page belongs is started, the configuration box function can be called to traverse the preset array, and the box adding step will be executed each time the traversal is performed. Each time a box is created, the preset addBox method will be called. Inside the addBox method, a function needs to be passed. This function is addbox. This function requires the name of the box to be added and the name of the corresponding target protocol. The internal implementation of the function includes the following steps (1) to (5).
[0063] Step (1) determines whether the name of the target protocol exists and whether the name of the box to be added exists. If the name of the target protocol and / or the box to be added does not exist, return and continue to traverse the next box in the preset array. If both exist, continue to perform the following step (2).
[0064] In step (2), the conformsToProtocol protocol method is used to detect whether the box to be created complies with the preset module loading protocol (boxLoad protocol). If so, the process proceeds to step (3). If not, the process returns to continue traversing the next box in the preset array. The boxLoad protocol contains a method for initializing each box in the preset page.
[0065] In step (3), the target protocol name is used as the key to retrieve the box to be added from the preset dictionary storing boxes and protocols. The preset boxbinding function is then called to bind the protocol to the box. The boxbinding function requires two parameters: one parameter is the protocol to be bound, and the other parameter is the object to bind the protocol to, that is, the box to which the protocol is to be bound. The internal implementation of this function first determines whether these two parameters exist. If both parameters exist, the function proceeds to step (4).
[0066] In step (4), use the conformsToProtocol function to determine whether the box complies with the protocol to be bound. If not, return directly. If it complies, continue with the subsequent step (5).
[0067] Step (5) establishes a synchronization lock, which is @synchronized. The synchronization lock is used to prevent a box from registering two protocols at the same time, and synchronized locks self. This step finds the bound object through the protocol. Use the NSStringFromProtocol method to find a key value. This key is the string name of the protocol. Use the key to find the corresponding client from the dictionary ClientDictionary that stores the binding relationship between the protocol and the object. Determine whether the type of this client is correct. If it is correct, get the object of this client. The object of this client is box. Client is a further encapsulation of box. The client object contains the properties of box. If the above client object exists, it means that the box has registered the protocol. If it does not exist, convert the protocol parameter obtained by the boxbinding function into a string type key, and create a client object at the same time. A parameter needs to be passed into this client object, and this parameter is a box. The specific code implementation process can be as follows:
[0068]
[0069] Each time you launch the application to which the preset page belongs, you bind the protocol, establish a relationship between the protocol and each box, and save the relationship, laying the foundation for subsequent calls. At the same time, you encapsulate each box as an object, using the corresponding protocol name as the key and the encapsulated object as the value to store it in the preset dictionary, which helps lay the foundation for subsequent interface design and calls.
[0070] After completing the registration and protocol binding of the target box, the following step S103 may be performed to design a calling interface so as to implement the calling of the target box through the calling interface.
[0071] Step S103: Create a calling interface, where the calling interface is used to call a target box in a preset dictionary that is bound to the target protocol through the target protocol.
[0072] During the specific implementation process, when making a box call, a static method can be defined to facilitate the interface call. For example, this static method can be defined as the box_caller function. The box_caller function requires three parameters. The first parameter is the protocol name p, the second parameter is a selector to be called, which is a function pointer used to determine whether the function to be called can be called, and the third parameter is the function func to be called. After these functions are passed in, the internal implementation needs to be written. The internal implementation is:
[0073]
[0074] First, the protocol name p is passed in and a protocol is generated through @protocol; then, the client management object is obtained through defaultCenter. This management object is a service object that complies with the protocol. After obtaining this service, the respondsToSelector method is used to determine whether the service complies with the selector method. Determining whether the selector method is complied with is actually determining whether the method in the service can be called, which can avoid program crashes. If the service does not comply with the selector, the service needs to be set to empty (nil). If the service complies with the selector method, the function func to be called is called through the service to complete the method call.
[0075] In this way, a simple interface box_callerWithSelector(p, selector, func) can be provided to the outside world, which uses the object to call the method fun and uses the selector to simplify the operation.
[0076] By establishing static method calls, calls can be made faster. You only need to define a protocol for the box, and then you can call the box using the protocol as a bridge without importing the entire file, which can effectively reduce the coupling between the caller and the callee.
[0077] Furthermore, after creating the call interface, you can pass in the corresponding parameters as needed to implement calls between boxes. The specific calling steps may include: obtaining the protocol name corresponding to the target function, the target function pointer selector, and the target function, where the target function is the function to be called, and the target function pointer is used to determine whether the target function can be called; and calling the target function by passing the protocol name, target function pointer selector, and target function into the call interface.
[0078] Accordingly, by passing the protocol name, target function pointer selector, and target function into the call interface, the process of calling the target function can include: generating a protocol using the passed protocol name; obtaining the client management object through defaultCenter, which is a service object that complies with the protocol; and determining whether the service complies with the selector method through the respondsToSelector method. If so, the target function is called through the service; if not, the service is set to nil. For specific implementation, please refer to the internal implementation process of the box_caller function mentioned above.
[0079] In summary, the function module calling method provided by the embodiments of the present invention only requires creating a protocol for the target function module to be called. The target function module can then be called according to the protocol and the created calling interface, making it more convenient and efficient to call the target function module. Furthermore, calls between function modules do not require mutual references, effectively eliminating the coupling issues caused by mutual references between function modules, reducing the dependencies between function modules, and significantly reducing the workload of maintaining and updating these function modules.
[0080] The second embodiment of the present invention provides a function module calling device, which is used to execute the function module calling method provided in the first embodiment, and is applied to call the function module in the IOS system. Figure 3 As shown, the function module calling device 30 includes:
[0081] a registration module 31 configured to, in response to a trigger operation for loading a preset page, associate and store each target functional module and its corresponding target protocol contained in the preset page in a preset dictionary, and register the corresponding relationship between each target functional module and target protocol in a preset array, wherein the target protocol is pre-created for the target functional module and defines the functional functions contained in the target functional module;
[0082] The binding module 32 is configured to, in response to a triggering operation of starting the application to which the preset page belongs, traverse the preset array and, for each target functional module traversed, perform the following creation and binding steps:
[0083] Detecting whether the name of the target functional module and the corresponding target protocol meet a preset configuration condition, and if so, obtaining the target functional module from the preset dictionary;
[0084] Binding the acquired target functional module to the corresponding target protocol by calling a preset module binding function, including: determining whether the target functional module complies with the target protocol through a conformsToProtocol function; if so, establishing a synchronization lock; searching for the target functional module to be bound through the target protocol; encapsulating the found target functional module into an object; and reassigning the object to the target protocol in the preset dictionary;
[0085] The interface creation module 33 is used to create a calling interface, where the calling interface is used to call the target function module in the preset dictionary that is bound to the target protocol through the target protocol.
[0086] In an optional embodiment, the above-mentioned function module calling device 30 also includes: a parameter acquisition module 34, used to obtain the protocol name, target function pointer selector and target function corresponding to the target function, wherein the target function is the function function that needs to be called, and the target function pointer is used to determine whether the target function can be called; a calling module 35, used to call the target function by passing the protocol name, target function pointer selector and target function into the calling interface.
[0087] In an optional embodiment, the above-mentioned calling module 35 is used to: generate a protocol through the passed-in protocol name; obtain the client management object through defaultCenter, and the client management object is a service object that complies with the protocol; through the respondsToSelector method, determine whether the service complies with the selector method, if so, call the target function through the service, if not, set the service to empty.
[0088] In an optional embodiment, the above-mentioned binding module 32 is used to: obtain the target functional module and the protocol name of the corresponding target protocol, and detect whether the protocol name and the target functional module both exist; if so, detect whether the target functional module complies with the preset module loading protocol through the conformsToProtocol protocol method; if so, determine whether the target functional module and the name of the corresponding protocol meet the preset configuration conditions, wherein the module loading protocol is used to initialize the target functional module.
[0089] In an optional embodiment, the above-mentioned binding module 32 is used to: obtain the string name of the target protocol through the NSStringFromProtocol method as the key value; search the corresponding client through the key value in the preset dictionary to determine whether the type of the client is correct, and if correct, obtain the object of the client, wherein the object object of the client is the corresponding target function module, the client is a further encapsulation of the target function module, and the client object contains the properties of the target function module; if the client object does not exist, convert the target protocol into a string type key, create a client object, and pass the parameters of the target function module into the client object.
[0090] In an optional embodiment, the target function module is a box or a function for implementing the target function.
[0091] It should be noted that the functional module calling device 30 provided in the embodiment of the present invention has the same implementation principle and technical effects as the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, please refer to the corresponding content in the aforementioned method embodiment.
[0092] In addition, the third embodiment of the present invention also provides an electronic device, including a processor and a memory, wherein the memory is coupled to the processor, and the memory stores instructions, which, when executed by the processor, enable the electronic device to execute the steps of the function module calling method provided in the above-mentioned first embodiment.
[0093] Figure 4 4 shows a block diagram of an exemplary electronic device 400. Figure 4 As shown, electronic device 400 includes memory 402, memory controller 404, one or more (only one is shown) processors 406, peripheral interface 408, network module 410, input / output module 412, display module 414, etc. These components communicate with each other via one or more communication buses / signal lines 416.
[0094] The memory 402 can be used to store software programs and modules, such as the function module calling method and program instructions / modules corresponding to the device in the embodiment of the present invention. The processor 406 executes various functional applications and data processing by running the software programs and modules stored in the memory 402, such as the function module calling method provided in the embodiment of the present invention.
[0095] The memory 402 may include a high-speed random access memory and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. The processor 406 and other possible components may access the memory 402 under the control of the storage controller 404.
[0096] The peripheral interface 408 couples various input / output devices to the processor 406 and the memory 402. In some embodiments, the peripheral interface 408, the processor 406, and the memory controller 404 can be implemented in a single chip. In other embodiments, they can be implemented in separate chips.
[0097] The network module 410 is used to receive and send network signals, which may include wireless signals or wired signals.
[0098] The input / output module 412 is used to provide user input data to enable user interaction with the electronic device. The input / output module 412 can be, but is not limited to, a mouse, a keyboard, and a touch screen. The user can use the input / output module 412 to launch the application to which the preset page belongs and trigger the loading of the preset page.
[0099] The display module 414 provides an interactive interface (e.g., a user interface) between the electronic device 400 and the user or is used to display image data for the user's reference. In this embodiment, the display module 414 can be a liquid crystal display or a touch display. If it is a touch display, it can be a capacitive touch screen or a resistive touch screen that supports single-point and multi-point touch operations. Supporting single-point and multi-point touch operations means that the touch display can sense touch operations generated simultaneously from one or more locations on the touch display and transmit the sensed touch operations to the processor for calculation and processing.
[0100] I understand. Figure 4 The structure shown is for illustration only. The electronic device 400 may also include Figure 4 More or fewer components than shown, or with Figure 4 Different configurations shown. Figure 4 Each component shown in the figure can be implemented by hardware, software or a combination thereof.
[0101] A fourth embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-mentioned method embodiments. If the functional unit integrated in the function module calling device described in the second embodiment of the present invention is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the process of the function module calling method of the first embodiment described above, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, the computer program can implement the steps of each of the above-mentioned method embodiments. The computer program includes computer program code, which can be in source code form, object code form, executable file, or some intermediate form. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal, and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practices in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practices, computer-readable media does not include electrical carrier signals and telecommunication signals.
[0102] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a portion of code, and the module, program segment or a portion of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or can be implemented using a combination of dedicated hardware and computer instructions.
[0103] In addition, the functional modules in the various embodiments of the present invention may be integrated together to form an independent part, or each module may exist independently, or two or more modules may be integrated to form an independent part.
[0104] It should be noted that, in this document, the terms "comprise," "include," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a list of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a..." does not preclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.
[0105] The foregoing description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Various modifications and variations are readily apparent to those skilled in the art. Any modifications, equivalent substitutions, improvements, and the like made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention. It should be noted that similar reference numerals and letters denote similar items in the following figures. Therefore, once an item is defined in one figure, it need not be further defined or explained in subsequent figures.< / nsobject>
Claims
1. A function module calling method, characterized in that: Applied to calling a function module in an IOS system, the method includes: In response to a trigger operation of loading a preset page, each target functional module and its corresponding target protocol included in the preset page are associated and stored in a preset dictionary, and the corresponding relationship between each target functional module and the target protocol is registered in a preset array, wherein the target protocol is pre-created for the target functional module and defines the functional functions included in the target functional module; In response to a trigger operation of starting the application to which the preset page belongs, the preset array is traversed, and for each target functional module traversed, the following creation and binding steps are performed: Detecting whether the name of the target functional module and the corresponding target protocol meet a preset configuration condition, and if so, obtaining the target functional module from the preset dictionary; Binding the acquired target functional module to the corresponding target protocol by calling a preset module binding function, including: determining whether the target functional module complies with the target protocol through a conformsToProtocol function; if so, establishing a synchronization lock; searching for the target functional module to be bound through the target protocol; encapsulating the found target functional module into an object; and reassigning the object to the target protocol in the preset dictionary; A calling interface is created, where the calling interface is used to call a target function module in the preset dictionary that is bound to the target protocol through the target protocol.
2. The method according to claim 1, wherein After creating the calling interface, the following steps are also included: Obtain the protocol name, target function pointer selector, and target function corresponding to the target function, wherein the target function is the function to be called, and the target function pointer is used to determine whether the target function can be called; The target function is called by passing the protocol name, target function pointer selector and target function into the calling interface.
3. The method according to claim 2, wherein The calling of the target function by passing the protocol name, the target function pointer selector and the target function into the calling interface includes: Generate a protocol by passing in the protocol name; Obtain the client management object through defaultCenter. The client management object is a service object that complies with the protocol. Through the respondsToSelector method, it is determined whether the service complies with the selector method. If so, the target function is called through the service. If not, the service is set to empty.
4. The method according to claim 1, wherein The detecting whether the name of the target functional module and the corresponding target protocol meets the preset configuration conditions includes: Obtain the target functional module and the protocol name of the corresponding target protocol, and detect whether the protocol name and the target functional module both exist; If it exists, the conformsToProtocol protocol method is used to detect whether the target functional module complies with the preset module loading protocol. If it does, it is determined that the name of the target functional module and the corresponding protocol meet the preset configuration conditions, wherein the module loading protocol is used to initialize the target functional module.
5. The method according to claim 1, wherein The step of searching for a target functional module to be bound through the target protocol includes: Get the string name of the target protocol as the key value through the NSStringFromProtocol method; Search the corresponding client by the key value in the preset dictionary, determine whether the type of the client is correct, and if so, obtain the object of the client, wherein the object of the client is the corresponding target functional module, the client is a further encapsulation of the target functional module, and the client object contains the attributes of the target functional module; If the client object does not exist, the target protocol is converted into a string type key, and a client object is created, and the parameters of the target function module are passed into the client object.
6. The method according to claim 1, wherein The target function module is a box or a function for realizing the target function.
7. A function module calling device, characterized in that: The device comprises: a registration module, configured to, in response to a triggering operation of loading a preset page, associate and store each target functional module and its corresponding target protocol contained in the preset page in a preset dictionary, and register the corresponding relationship between each target functional module and target protocol in a preset array, wherein the target protocol is pre-created for the target functional module and defines the functional functions contained in the target functional module; The binding module is configured to, in response to a triggering operation of starting the application to which the preset page belongs, traverse the preset array and, for each target functional module traversed, perform the following creation and binding steps: Detecting whether the name of the target functional module and the corresponding target protocol meet a preset configuration condition, and if so, obtaining the target functional module from the preset dictionary; Binding the acquired target functional module to the corresponding target protocol by calling a preset module binding function, including: determining whether the target functional module complies with the target protocol through a conformsToProtocol function; if so, establishing a synchronization lock; searching for the target functional module to be bound through the target protocol; encapsulating the found target functional module into an object; and reassigning the object to the target protocol in the preset dictionary; The interface creation module is used to create a calling interface, wherein the calling interface is used to call the target function module bound to the target protocol in the preset dictionary through the target protocol.
8. The device according to claim 7, wherein The device further comprises: A parameter acquisition module is used to obtain the protocol name corresponding to the target function, the target function pointer selector, and the target function, wherein the target function is a function function that needs to be called, and the target function pointer is used to determine whether the target function can be called; The calling module is used to call the target function by passing the protocol name, target function pointer selector and target function into the calling interface.
9. An electronic device, characterized in that: The electronic device comprises a processor and a memory, wherein the memory is coupled to the processor and stores instructions. When the instructions are executed by the processor, the electronic device executes the steps of the method according to any one of claims 1 to 6.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Message distribution method, message distribution device, electronic device and storage medium
CN109286558A
System and method of application development using replaceable self-contained components (RSCCS)
US8392877B1