CN116225576B - Application program data environment switching method and device, electronic equipment and medium - Google Patents

Application program data environment switching method and device, electronic equipment and medium Download PDF

Info

Publication number
CN116225576B
CN116225576B CN202310505351.7A CN202310505351A CN116225576B CN 116225576 B CN116225576 B CN 116225576B CN 202310505351 A CN202310505351 A CN 202310505351A CN 116225576 B CN116225576 B CN 116225576B
Authority
CN
China
Prior art keywords
data environment
environment
value
character string
local data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202310505351.7A
Other languages
Chinese (zh)
Other versions
CN116225576A (en
Inventor
王辉
唐如意
叶松林
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chongqing Selis Phoenix Intelligent Innovation Technology Co ltd
Original Assignee
Chengdu Seres Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chengdu Seres Technology Co Ltd filed Critical Chengdu Seres Technology Co Ltd
Priority to CN202310505351.7A priority Critical patent/CN116225576B/en
Publication of CN116225576A publication Critical patent/CN116225576A/en
Application granted granted Critical
Publication of CN116225576B publication Critical patent/CN116225576B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44536Selecting among different versions
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Retry When Errors Occur (AREA)
  • Stored Programmes (AREA)

Abstract

The application provides a data environment switching method and device of an application program, electronic equipment and a medium. The method comprises the following steps: creating an enumeration type and a global character string constant, and adding an original value for characterizing a data environment for the enumeration type; acquiring a local data environment of an application program, determining an enumeration value, and returning to a global data interface of the local data environment according to the enumeration value; after a shaking event is monitored, determining a target data environment, and comparing a character string variable of the target data environment with a character string variable of a local data environment; when the string variable of the target data environment is not equal to the string variable of the local data environment, the target data environment is taken as a value, the global string constant is taken as a key, and the local data environment is updated by the value and the key so as to switch the local data environment into the target data environment. The method and the device can improve the efficiency of data environment switching, remarkably reduce error rate, have high fault tolerance and support frequent switching for any times.

Description

Application program data environment switching method and device, electronic equipment and medium
Technical Field
The present invention relates to the field of application program development technologies, and in particular, to a method, an apparatus, an electronic device, and a medium for switching data environments of an application program.
Background
There are generally two types of existing application data environment switching schemes: one is manual switching, and the other is realized through a unified interface provided by the back end. The method of manually switching the data environment is cumbersome, inefficient, and may require simultaneous switching from front to back to operate smoothly. The unified interface scheme provided by the back end also has the problems of low fault tolerance, incapability of switching frequently and the like. These problems can lead to serious waste of human resources and large workload in the development and testing stages, and the whole process may be paralyzed when errors occur at any one of the front end and the rear end.
Disclosure of Invention
In view of this, the embodiments of the present application provide a method, an apparatus, an electronic device, and a medium for switching a data environment of an application program, so as to solve the problems in the prior art that the switching process of the data environment is complicated, the efficiency is low, the fault tolerance is low, frequent switching cannot be performed, and the waste of human resources is serious.
In a first aspect of an embodiment of the present application, a method for switching a data environment of an application program is provided, including: creating an enumeration type and a global character string constant, adding an original value for representing the data environment for the enumeration type, and identifying the data environment by the global character string constant; acquiring a local data environment used by an application program, determining an enumeration value corresponding to an original value of the local data environment, and returning to a global data interface of the local data environment according to the enumeration value; after a shaking event is monitored, determining a target data environment selected by a user, and comparing a character string variable of the target data environment with a character string variable of a local data environment; when the string variable of the target data environment is not equal to the string variable of the local data environment, the target data environment is taken as a value, the global string constant is taken as a key, and the local data environment is updated by the value and the key so as to switch the local data environment into the target data environment.
In a second aspect of the embodiments of the present application, there is provided a data environment switching device for an application program, including: the creation module is configured to create an enumeration type and a global character string constant, and adds an original value for representing the data environment for the enumeration type, wherein the global character string constant is used for identifying the data environment; the determining module is configured to acquire a local data environment used by the application program, determine an enumeration value corresponding to an original value of the local data environment, and return a global data interface of the local data environment according to the enumeration value; the comparison module is configured to determine a target data environment selected by a user after monitoring a shaking event, and compare a character string variable of the target data environment with a character string variable of a local data environment; and the updating module is configured to update the local data environment by using the value and the key with the target data environment as a value and the global character string constant as a key when the character string variable of the target data environment is unequal to the character string variable of the local data environment so as to switch the local data environment into the target data environment.
In a third aspect of the embodiments of the present application, there is provided an electronic device including a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the above method when executing the program.
In a fourth aspect of the embodiments of the present application, there is provided a computer readable storage medium storing a computer program which, when executed by a processor, implements the steps of the above method.
The above-mentioned at least one technical scheme that this application embodiment adopted can reach following beneficial effect:
the method comprises the steps that an enumeration type and a global character string constant are created, an original value for representing a data environment is added for the enumeration type, and the global character string constant is used for identifying the data environment; acquiring a local data environment used by an application program, determining an enumeration value corresponding to an original value of the local data environment, and returning to a global data interface of the local data environment according to the enumeration value; after a shaking event is monitored, determining a target data environment selected by a user, and comparing a character string variable of the target data environment with a character string variable of a local data environment; when the string variable of the target data environment is not equal to the string variable of the local data environment, the target data environment is taken as a value, the global string constant is taken as a key, and the local data environment is updated by the value and the key so as to switch the local data environment into the target data environment. According to the method and the device, the functions of shaking and detecting shaking of the iOS system level are fully utilized, the implementation steps and logic of data environment switching are greatly simplified, the efficiency of data environment switching is improved, the error rate is remarkably reduced, the fault tolerance is high, and frequent switching of any times is supported.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following description will briefly introduce the drawings that are needed in the embodiments or the description of the prior art, it is obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flowchart of a data environment switching method of an application provided in an embodiment of the present application;
fig. 2 is a schematic structural diagram of a data environment switching device of an application program according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system configurations, techniques, etc. in order to provide a thorough understanding of the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
As background art content, there are two types of environment switching schemes currently in common use: the first is manual switching, namely, the global interface in the code is manually replaced at first, then manually packaged, and the edition is reissued, and then downloaded and installed for use by other personnel; the second is that the back end provides a unified interface, when each application is started, the current global interface is obtained from the inside of the interface, the unified interface returns the real environment to the client in a data mode, and the client sets the real environment as the global interface for further use. Since these two schemes may involve the backend and be implemented manually, the following problems may occur:
(1) The front end and the back end may need to be simultaneously switched to operate smoothly, resulting in serious waste of human resources.
(2) The front end needs to be repackaged after switching the environment, and has the advantages of complex steps, large workload, time waste and low efficiency.
(3) Frequent switching is not possible and it takes too much time and cost to switch once.
(4) If any one of the front end and the rear end goes wrong, the whole flow is completely paralyzed, and the fault tolerance is too low.
In view of this, in order to solve the above-mentioned problems, an embodiment of the present application provides a data environment switching method for an application program. The method and the device for updating the local data environment comprise the steps of creating an enumeration type and a global character string constant to represent the data environment, judging a target data environment selected by a user according to a shaking event, and updating the local data environment by utilizing key value pairs. The data environment can be switched in the running process of the application program, so that the switching efficiency is improved, and the tedious steps of frequent packing and version resending are avoided. The method and the device reduce the burden of the rear-end interface and reduce the problems of human resource waste and low fault tolerance. In addition, the local data environment is updated through the key value pairs, so that the dynamic switching of the data environment is realized, and the problems of human resource waste and low fault tolerance are reduced.
The technical scheme of the application is described in detail below with reference to the accompanying drawings and specific embodiments.
Fig. 1 is a flowchart of a data environment switching method of an application program according to an embodiment of the present application. The data environment switching method of the application of fig. 1 may be performed by the application. As shown in fig. 1, the data environment switching method of the application program specifically may include:
s101, creating an enumeration type and a global character string constant, and adding an original value for representing a data environment for the enumeration type, wherein the global character string constant is used for identifying the data environment;
s102, acquiring a local data environment used by an application program, determining an enumeration value corresponding to an original value of the local data environment, and returning to a global data interface of the local data environment according to the enumeration value;
s103, after a shaking event is monitored, determining a target data environment selected by a user, and comparing a character string variable of the target data environment with a character string variable of a local data environment;
and S104, when the character string variable of the target data environment is unequal to the character string variable of the local data environment, taking the target data environment as a value, taking the global character string constant as a key, and updating the local data environment by using the value and the key so as to switch the local data environment into the target data environment.
Firstly, explaining some technical terms involved in the practical application scene in the embodiment of the present application, the specific terms may include the following:
in the field of iOS program development, enumeration (Enumeration) is a special data type that allows a developer to define a finite set of mutually different values that are typically used to represent a related set of constants. The use of enumeration may make the code more readable and legible while reducing the probability of errors occurring. In Objective-C, the enumerated definitions typically use enum keywords, while in Swift, the enum keywords are used to define the enumerated types.
Enumeration is often used in iOS development to represent a limited set of options, states, or configurations. For example, you might use enumeration to represent different screen directions (landscape or portrait) of an application or the status of a network request (success, failure, timeout, etc.).
enum: an identifier representing an enumeration type.
ServerEnvironment: representing a custom enumeration type.
String: the character string type may be used to represent text data.
Jk_server environment: representing custom string constants.
Any: may be used to represent any type.
UserDefaults: indicating that the iOS accesses a locally stored data type.
as: representing a type conversion identifier.
rawValue: representing the original value, i.e., the value that the enumeration type set at creation time.
nil: representing that the current data is empty.
func: representing a method identifier.
case: an identifier representing the enumerated value.
In some embodiments, an enumeration type named ServerEnvironment is first created, the enumeration type having an original value in the form of a String (i.e., the original value of the type String). Enumeration types are commonly used to represent a set of related limited options that may help us improve code readability and security. Here, the embodiment of the present application defines three options for the server environment enumeration type, respectively: release, develop and test, represent three different data environments.
Further, in the embodiment of the present application, 3 cases (original values) are added for the enumerated type ServerEnvironment, and are named as release, develop, test respectively, and specific descriptions of the three cases are shown in the following table:
table 1 ServerEnvironment original value table
Further, embodiments of the present application also create a global string constant named jk_serverenvironment, which is also "jk_serverenvironment". This constant will be used as a key when later reading and storing the data environment from the local, using the global string constant jk_serverenvironment to identify and distinguish between different environment configurations.
In some embodiments, obtaining a local data environment used by an application and determining an enumerated value corresponding to an original value of the local data environment includes:
creating a value variable of the character string type, and setting an initial value of the value variable of the character string type as an enumeration value;
transmitting the global character string constant as a parameter to a preset acquisition method, and acquiring a stored local data environment from local default setting by using the preset acquisition method;
and assigning the value variable of the character string type by using the local data environment, creating an environment variable, and transmitting the original value parameter so as to determine an enumeration value according to the value variable of the character string type.
Specifically, in the embodiment of the present application, by creating a method named getEnvironment () (i.e. a data environment obtaining method, which is used to obtain a data environment of a current application program and return a corresponding ServerEnvironment enumeration value, in practical application, a specific implementation procedure and principle of the getEnvironment () method may include the following:
step 1: firstly, creating a variable value of a character string type, and setting an initial value of the variable value as an enumeration value of a development environment; for example: a variable value of the String type is created, and the default value is set as the original value of a "development" option of the ServerEnvironment enumeration type.
Step 2: invoking a method for retrieving a stored data environment value from a user default setting, the method requiring a parameter to be passed, the parameter being a string constant for identifying the data environment; for example: a UserDefaults standard value method is called, and the method is used for acquiring a corresponding value (value) from user default settings (UserDefaults) according to a provided key, and transmitting a global string constant jk_serverenvironment as a parameter for key. After the userdefaults standard value method is performed, a result is obtained.
Step 3: the type of results returned by the userdefaults standard value method is optional and needs to be converted into a string type. If the conversion is successful and the result is not null, then the result is assigned to value. That is, the value type returned by the UserDefaults. Standard. Value (for Key:) method is an optional Any type, namely Any-! It needs to be converted to String type. If the conversion is successful and the returned character string is not null, assigning the character string to the value, otherwise, not performing any operation.
Step 4: an object of an enumeration type (environment variable) is created and specific enumeration values are determined from the value values. In this process an original value parameter needs to be transferred. In practical applications, an object of a server environment enumeration type (enumeration object) needs to be created. Creating a variable env (environment variable), transmitting the value to a rawValue parameter (namely an original value parameter) of a ServerEnvironment method, wherein the method is used for creating a ServerEnvironment enumeration object, providing a character string parameter matched with a case original value in the enumeration type, returning a corresponding enumeration value, and finally creating a ServerEnvironment object and assigning a result to the env.
Step 5: since creating an enumeration object may fail, it is necessary to check whether the result is empty. If empty, taking the test environment as a default value; if not empty, it remains unchanged. That is, it is necessary to check whether env is nil. If the value is nil, assigning a test value of the ServerEnvironment to env as a default value; if not nil, no action has to be performed. Finally, the final env is returned.
According to the technical scheme provided by the embodiment of the application, an enumeration value is created through the locally read value of the character string representing the current data environment, and then the enumeration value is assigned to the global variable, so that the enumeration value can be conveniently called in various places of the program. Briefly, embodiments of the present application acquire a data environment configuration of a current application using a getEnvironment () method, and return a corresponding ServerEnvironment enumeration value according to the configuration. The specific implementation of the method comprises the steps of reading environment configuration from UserDefaults, processing read data, creating a ServerEnvironment enumeration object, and finally returning the object.
In some embodiments, returning the global data interface of the local data environment in accordance with the enumerated value includes:
And storing the enumerated values in the current environment variables, judging the local data environment where the application program is currently located according to the values of the current environment variables, and returning global data interfaces corresponding to the local data environment, wherein the local data environment comprises a production environment, a development environment and a test environment.
Specifically, after the local data environment used by the current application program is acquired by using the getEnvironment () method, the embodiment of the present application creates a method named getb aseurl () which is used to return the global data interface in the current data environment. In practical application, the specific implementation process and principle of the getbase Url () method may include the following:
first, the getEnvironment () method created in the foregoing embodiment is called to acquire the current data environment. The result returned by the getEnvironment () method is a ServerEnvironment enumeration value that represents the data environment in which the current application is located, and the result is stored in the variable currentEnvironment.
The data environment in which the user is currently located is determined according to the value of currentEnvironment (i.e., the value enumerated by ServerEnvironment), for example: when the value is release, the current production environment is represented, and a global data interface of the production environment is returned at the moment; when the value is the development, the current development environment is represented, and a global data interface of the development environment is returned at the moment; when the value is test, the current test environment is represented, and the global data interface of the test environment is returned.
That is, the embodiment of the application returns the global data interface under the corresponding data environment according to the data environment of the current application program through the created getbase Url () method. The specific implementation of the method comprises the steps of obtaining an enumeration value of a current data environment, judging the environment according to the enumeration value, and finally returning to a corresponding global data interface.
In some embodiments, before determining the user selected target data environment after listening for the shake event, the method of embodiments of the present application further comprises:
configuring a shaking event method triggered when a user shakes equipment, and judging shaking event type parameters in the shaking event method to determine the type of a current shaking event;
creating a prompt box by using a preset method for creating a prompt box controller, and setting the title, the message and the prompt box style of the prompt box;
adding a selection item for clicking to switch to the data environment for the prompt box, and setting a title for the selection item according to the data environment, wherein the title of the selection item comprises switching to the development environment and switching to the test environment.
Specifically, in order to facilitate the switching of data environments in the development and testing stages, the embodiment of the application rewrites a func motionBegan (motion: uieventsubtype, with event: UIEvent |) method of the iOS system, realizes the judgment of the parameters of the type of the shaking event, creates a prompt box, and adds the functions of selecting items and the like. The following describes details of the rewriting process and principle of the func-motionBegan (motion: uieventsubtype, with event: UIEvent |) method in conjunction with specific embodiments, and may specifically include the following:
First, it is determined whether the motion parameter value of the method is equal to the motionShake enumerated by Uievent.EventSubtype. If equal to motionShake, the user triggers the action of shaking the device, and the device continues to execute. In practical applications, the motion is an enumeration value representing which type of shaking event is currently being performed, and the motionShake is one of numerous enumeration values of the motion representing that the current type of shaking event is the mobile phone being shaking.
A popup box alert VC (also called a prompt box) is created through a UIAlertController (title:, message:, preferredStyle:) method (namely a prompt box creation controller method) of a system, and the popup box is used for enabling a user to autonomously switch data environments. Setting the pop-up box with the title of "context switch", the message of "click switch background context" and the setting style of actionSheet.
Thereafter, a selection entry devAct for switching to the development environment is added to the alert VC using the UIAlertAction (title:, style:). The item is set up as a "development environment" and the style is default. The previously created setEnvironment method is called in the trailing closure of the method, and the character string of development is transmitted in, so that the switching and the storage of the development environment are realized.
Likewise, using the UIAlertAction (title:, style:) method, a selection entry testAct is added to the alert vc to switch to the test environment. The item is set to be entitled "test environment" and the style is default. And calling a setEnvironment method in the trailing closure of the method, and transmitting a character string of 'test' to realize the switching and the storage of a test environment.
Here, although there are three values of the ServerEnvironment enumeration, only entries of the development environment and the test environment are created in the above-described embodiment. As the functionality is designed primarily for developers and testers to switch environments during the development and testing phases. Once the application is formally online, the data interface is fixed and no switching environment is required. Thus, no switching of production environments is considered here nor is it necessary to create an entry for a production environment.
Briefly, the above embodiments introduce the rewrite principle and procedure of the motionBegan method, which will be triggered when the user shakes the handset. The motionBegan method can be understood as an event processing method for processing a motion event triggered when a user shakes the device. This approach is mainly used in the development and testing phases to help developers and testers switch between different data environments (e.g., development environment and testing environment). The specific implementation of the method comprises the steps of firstly judging whether a user really shakes the mobile phone, if so, popping up a selection frame, wherein two options exist in the selection frame: one is to switch to the development environment and the other is to switch to the test environment. After the user selects, the data environment is switched to the corresponding data environment and stored. No option to switch to the production environment is provided in this method, as this functionality is mainly used in the development and testing phases. After the application is formally online, the data interface is fixed, and the environment is not required to be switched.
In some embodiments, upon listening for a shake event, determining a user selected target data environment includes:
responding to shaking operation of a user on the equipment, calling back the configured shaking event method, and judging whether to switch the data environment according to the type of the current shaking event;
when judging to switch the data environment, popping up a prompt box for a user to select the switched data environment;
and according to the title selection of the selection item by the user, taking the data environment selected by the user to be switched to as a target data environment.
Specifically, when the user wants to switch the data environment, the user only needs to shake the mobile phone, after the mobile phone monitors the shake event, the mobile phone will call back a func motion began (motion: uieventsubtype, with event: UIEvent |) method, and pop up a selection box for the user to select the environment that wants to switch. After the user selects, the setenvironment method is called, and the current environment is set as the target environment. And simultaneously, the UserDefaults.Standard.setValue and the UserDefaults.Standard.synchonize method are called to store the target data environment locally, so that the user selection is remembered by default when the app is restarted next time, and normal use can be performed.
In some embodiments, updating the local data environment with the value and the key with the target data environment as the value and the global string constant as the key comprises:
and calling a preset data environment updating method, taking the target data environment as a value and transmitting the target data environment into the data environment updating method, taking the global character string constant as a key and transmitting the global character string constant into the data environment updating method, updating the local data environment by using the value and the key, and storing the updated data environment to the local.
Specifically, the embodiment of the application also creates a method named setEnvironment (String) for setting the data environment when the user clicks the corresponding switch environment button. In practical applications, the specific implementation process and principle of the setEnvironment (String) method may include the following:
the method of UserDefaults.Standard.value (for Key:) is called to acquire the data environment currently stored locally, and the result returned by the method is a character string representing the current data environment, and the character string is stored in the variable savedValue.
It is determined whether the value of savedValue is equal to the incoming enviro, that is, two string variables are compared: savedValue and enviro. savedValue is the current data environment value obtained from the local store, enviro is the target data environment value entered as a parameter. It is necessary to determine whether these two values are equal to determine whether a data environment needs to be switched. If equal, it is stated that the current environment is already the environment that the user wants to switch, without switching again, at which point the method execution is directly interrupted. If not, the next step is continued.
The userdefaults standard method (i.e., the data environment update method) is called, enviro is taken as a value (i.e., the target data environment is taken as a value), jk_serverenvironment is taken as a key (i.e., the global string constant is taken as a key) and is transferred into the data environment update method, so that the data environment stored locally can be updated. The userdefaults standard method is then invoked and the new environment is immediately stored locally.
In practical applications, the data environment stored locally is updated by calling the userdefaults standard value method (i.e. the data environment updating method), and the new environment is saved locally immediately. First, the userdefaults standard value method is called, and enviro is entered as a value and jk_serverenvironment is entered as a key. This stores the new data environment value (enviro) and corresponding key (jk_serverenvironment) in the user default settings (UserDefaults) to enable updating the locally stored data environment.
Next, the UserDefaults. Standard. Synchonize method is invoked. This method will immediately write all unsaved changes to the local store, ensuring that the new data environment is immediately validated locally.
Briefly, a setenvironmental (String) method provided by embodiments of the present application sets a data environment according to a user's selection. The implementation process comprises the steps of acquiring a current locally stored data environment, judging whether updating is needed, and storing a new environment value to the local if updating is needed. I.e. change the current data environment by updating UserDefaults and ensure that the new environment is stored immediately locally.
In some embodiments, the method of embodiments of the present application further comprises:
when the starting of the application program is monitored, a global data interface acquisition method is called, a global data interface of a local data environment where the application program is currently located is obtained, and a data acquisition request is sent to a server to acquire application program display data returned by the server.
In practical application, when the app is started, in order to display data, the server data needs to be requested first, when the server data is requested, an interface under the current data environment is obtained by calling the getbase Url method provided by the foregoing embodiment, then a request is sent to the server, and the server returns the data to the app according to the sent request parameters.
According to the technical scheme provided by the embodiment of the application, the data environment is represented by creating an enumeration type and a global character string constant, a target data environment selected by a user is judged according to a shaking event, and a local data environment is updated by utilizing a key value pair. The data environment can be switched in the running process of the application program, so that the switching efficiency is improved, and the tedious steps of frequent packing and version resending are avoided. The method and the device reduce the burden of the rear-end interface and reduce the problems of human resource waste and low fault tolerance. In addition, the local data environment is updated through the key value pairs, so that the dynamic switching of the data environment is realized, and the problems of human resource waste and low fault tolerance are reduced.
Based on the technical scheme provided by the embodiment of the application, the embodiment of the application can complete the data environment switching of the application program by only one person at the front end, and no personnel is wasted. Only one time of packing is needed, the steps are simple, the time is short, and the efficiency is high. The embodiment of the application supports frequent switching for any number of times, and is more suitable for actual use scenes. The embodiment of the application is only responsible for switching by the front end, so that the error rate is obviously reduced, and the fault tolerance rate is high. According to the embodiment of the application, the functions of shaking and detecting shaking of the iOS system level are fully utilized, the steps and logic of implementation are greatly simplified, and any number of frequent switching is supported.
The following are device embodiments of the present application, which may be used to perform method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.
Fig. 2 is a schematic structural diagram of a data environment switching device of an application program according to an embodiment of the present application. As shown in fig. 2, the data environment switching device of the application program includes:
a creation module 201 configured to create an enumeration type and a global string constant, and add an original value for characterizing the data environment for the enumeration type, the global string constant being used to identify the data environment;
A determining module 202 configured to obtain a local data environment used by the application program, determine an enumeration value corresponding to an original value of the local data environment, and return a global data interface of the local data environment according to the enumeration value;
a comparison module 203 configured to determine a target data environment selected by a user after listening to a shaking event, compare a string variable of the target data environment with a string variable of a local data environment;
the updating module 204 is configured to update the local data environment with the value and the key with the target data environment as a value and the global string constant as a key so as to switch the local data environment to the target data environment when the string variable of the target data environment is not equal to the string variable of the local data environment.
In some embodiments, determination module 202 of FIG. 2 creates a string-type value variable, sets an initial value of the string-type value variable to an enumerated value; transmitting the global character string constant as a parameter to a preset acquisition method, and acquiring a stored local data environment from local default setting by using the preset acquisition method; and assigning the value variable of the character string type by using the local data environment, creating an environment variable, and transmitting the original value parameter so as to determine an enumeration value according to the value variable of the character string type.
In some embodiments, the determination module 202 of fig. 2 stores the enumerated values in the current environment variables, determines a local data environment in which the application is currently located according to the values of the current environment variables, and returns a global data interface corresponding to the local data environment, where the local data environment includes a production environment, a development environment, and a test environment.
In some embodiments, after the shaking event is monitored, the configuration module 205 of fig. 2 configures a shaking event method triggered when the user shakes the device before determining the target data environment selected by the user, and determines a shaking event type parameter in the shaking event method to determine a type of a current shaking event; creating a prompt box by using a preset method for creating a prompt box controller, and setting the title, the message and the prompt box style of the prompt box; adding a selection item for clicking to switch to the data environment for the prompt box, and setting a title for the selection item according to the data environment, wherein the title of the selection item comprises switching to the development environment and switching to the test environment.
In some embodiments, the comparison module 203 of fig. 2 is configured to call back the configured shake event method in response to the shake operation of the device by the user, and determine whether to switch the data environment according to the type of the current shake event; when judging to switch the data environment, popping up a prompt box for a user to select the switched data environment; and according to the title selection of the selection item by the user, taking the data environment selected by the user to be switched to as a target data environment.
In some embodiments, the update module 204 of fig. 2 invokes a preset data environment update method, passes the target data environment as a value into the data environment update method, passes the global string constant as a key into the data environment update method, updates the local data environment with the value and the key, and saves the updated data environment locally.
In some embodiments, the obtaining module 206 of fig. 2 invokes a global data interface obtaining method when it detects that the application is started, obtains a global data interface of a local data environment where the application is currently located, and sends a data obtaining request to the server to obtain application presentation data returned by the server.
It should be understood that the sequence number of each step in the foregoing embodiment does not mean that the execution sequence of each process should be determined by the function and the internal logic of each process, and should not limit the implementation process of the embodiment of the present application in any way.
Fig. 3 is a schematic structural diagram of the electronic device 3 provided in the embodiment of the present application. As shown in fig. 3, the electronic apparatus 3 of this embodiment includes: a processor 301, a memory 302 and a computer program 303 stored in the memory 302 and executable on the processor 301. The steps of the various method embodiments described above are implemented when the processor 301 executes the computer program 303. Alternatively, the processor 301, when executing the computer program 303, performs the functions of the modules/units in the above-described apparatus embodiments.
Illustratively, the computer program 303 may be partitioned into one or more modules/units, which are stored in the memory 302 and executed by the processor 301 to complete the present application. One or more of the modules/units may be a series of computer program instruction segments capable of performing a specific function for describing the execution of the computer program 303 in the electronic device 3.
The electronic device 3 may be an electronic device such as a desktop computer, a notebook computer, a palm computer, or a cloud server. The electronic device 3 may include, but is not limited to, a processor 301 and a memory 302. It will be appreciated by those skilled in the art that fig. 3 is merely an example of the electronic device 3 and does not constitute a limitation of the electronic device 3, and may include more or fewer components than shown, or may combine certain components, or different components, e.g., the electronic device may also include an input-output device, a network access device, a bus, etc.
The processor 301 may be a central processing unit (Central Processing Unit, CPU) or other general purpose processor, digital signal processor (Digital Signal Processor, DSP), application specific integrated circuit (Application SpecificIntegrated Circuit, ASIC), field programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 302 may be an internal storage unit of the electronic device 3, for example, a hard disk or a memory of the electronic device 3. The memory 302 may also be an external storage device of the electronic device 3, for example, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card) or the like, which are provided on the electronic device 3. Further, the memory 302 may also include both an internal storage unit and an external storage device of the electronic device 3. The memory 302 is used to store computer programs and other programs and data required by the electronic device. The memory 302 may also be used to temporarily store data that has been output or is to be output.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-described division of the functional units and modules is illustrated, and in practical application, the above-described functional distribution may be performed by different functional units and modules according to needs, i.e. the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-described functions. The functional units and modules in the embodiment may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit, where the integrated units may be implemented in a form of hardware or a form of a software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working process of the units and modules in the above system may refer to the corresponding process in the foregoing method embodiment, which is not described herein again.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and in part, not described or illustrated in any particular embodiment, reference is made to the related descriptions of other embodiments.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the embodiments provided in this application, it should be understood that the disclosed apparatus/computer device and method may be implemented in other ways. For example, the apparatus/computer device embodiments described above are merely illustrative, e.g., the division of modules or elements is merely a logical functional division, and there may be additional divisions of actual implementations, multiple elements or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection via interfaces, devices or units, which may be in electrical, mechanical or other forms.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed over a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in each embodiment of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated modules/units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the present application implements all or part of the flow in the methods of the above embodiments, or may be implemented by a computer program to instruct related hardware, and the computer program may be stored in a computer readable storage medium, where the computer program may implement the steps of the respective method embodiments described above when executed by a processor. The computer program may comprise computer program code, which may be in source code form, object code form, executable file or in some intermediate form, etc. The computer readable medium may include: any entity or device capable of carrying computer program code, a recording medium, a U disk, a removable hard disk, a magnetic disk, an optical disk, a computer Memory, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), an electrical carrier signal, a telecommunications signal, a software distribution medium, and so forth. It should be noted that the content of the computer readable medium can be appropriately increased or decreased according to the requirements of the jurisdiction's jurisdiction and the patent practice, for example, in some jurisdictions, the computer readable medium does not include electrical carrier signals and telecommunication signals according to the jurisdiction and the patent practice.
The above embodiments are only for illustrating the technical solution of the present application, and are not limiting thereof; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present application, and are intended to be included in the scope of the present application.

Claims (8)

1. A data environment switching method of an application program, applied to an IOS system, comprising:
creating an enumeration type and a global character string constant, and adding an original value for representing a data environment for the enumeration type, wherein the global character string constant is used for identifying the data environment;
acquiring a local data environment used by an application program, determining an enumeration value corresponding to an original value of the local data environment, and returning to a global data interface of the local data environment according to the enumeration value;
after a shaking event is monitored, determining a target data environment selected by a user, and comparing a character string variable of the target data environment with a character string variable of the local data environment;
When the character string variable of the target data environment is unequal to the character string variable of the local data environment, taking the target data environment as a value, taking the global character string constant as a key, and updating the local data environment by using the value and the key so as to switch the local data environment into the target data environment;
wherein the obtaining the local data environment used by the application program and determining the enumeration value corresponding to the original value of the local data environment comprises:
creating a value variable of a character string type, and setting an initial value of the value variable of the character string type as an enumeration value;
transmitting the global character string constant as a parameter to a preset acquisition method, and acquiring a stored local data environment from local default setting by using the preset acquisition method;
assigning the value variable of the character string type by utilizing the local data environment, creating an environment variable, and transmitting the original value parameter so as to determine an enumeration value according to the value variable of the character string type;
the returning the global data interface of the local data environment according to the enumeration value comprises the following steps:
And storing the enumeration value in a current environment variable, judging a local data environment where the application program is currently located according to the value of the current environment variable, and returning a global data interface corresponding to the local data environment, wherein the local data environment comprises a production environment, a development environment and a test environment.
2. The method of claim 1, wherein prior to determining the user selected target data environment after the listening for the shake event, the method further comprises:
configuring a shaking event method triggered when a user shakes equipment, and judging shaking event type parameters in the shaking event method to determine the type of a current shaking event;
creating a prompt box by using a preset method for creating a prompt box controller, and setting the title, the message and the prompt box style of the prompt box;
and adding a selection item for clicking to switch to the data environment for the prompt box, and setting a title for the selection item according to the data environment, wherein the title of the selection item comprises switching to the development environment and switching to the test environment.
3. The method of claim 2, wherein determining the user selected target data environment after the shake event is detected comprises:
Responding to shaking operation of a user on the equipment, callback is conducted on the configured shaking event method, and whether the data environment is switched or not is judged according to the type of the current shaking event;
when judging to switch the data environment, popping up the prompt box for the user to select the switched data environment;
and according to the title selection of the user in the selection item, taking the data environment selected by the user to be switched to as the target data environment.
4. The method of claim 1, wherein the updating the local data environment with the value and key with the target data environment as the value and the global string constant as the key comprises:
and calling a preset data environment updating method, taking the target data environment as a value and transmitting the target data environment into the data environment updating method, taking the global character string constant as a key and transmitting the global character string constant into the data environment updating method, updating the local data environment by using the value and the key, and storing the updated data environment to the local.
5. The method according to claim 1, wherein the method further comprises:
when the starting of the application program is monitored, a global data interface acquisition method is called, a global data interface of a local data environment where the application program is currently located is obtained, and a data acquisition request is sent to a server to acquire application program display data returned by the server.
6. A data environment switching device for an application program, applied to an IOS system, comprising:
the system comprises a creation module, a calculation module and a calculation module, wherein the creation module is configured to create an enumeration type and a global character string constant, and add an original value for representing a data environment for the enumeration type, and the global character string constant is used for identifying the data environment;
the determining module is configured to acquire a local data environment used by an application program, determine an enumeration value corresponding to an original value of the local data environment, and return a global data interface of the local data environment according to the enumeration value;
a comparison module configured to determine a target data environment selected by a user after a shake event is monitored, and compare a string variable of the target data environment with a string variable of the local data environment;
an updating module configured to update the local data environment with a value and a key with the target data environment as a value and the global string constant as a key when the string variable of the target data environment is not equal to the string variable of the local data environment, so as to switch the local data environment to the target data environment;
The determining module is further used for creating a value variable of the character string type, and setting an initial value of the value variable of the character string type as an enumeration value; transmitting the global character string constant as a parameter to a preset acquisition method, and acquiring a stored local data environment from local default setting by using the preset acquisition method; assigning the value variable of the character string type by utilizing the local data environment, creating an environment variable, and transmitting the original value parameter so as to determine an enumeration value according to the value variable of the character string type;
the determination module is further configured to store the enumerated value in a current environment variable, determine a local data environment where the application program is currently located according to the value of the current environment variable, and return a global data interface corresponding to the local data environment, where the local data environment includes a production environment, a development environment and a test environment.
7. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the method of any one of claims 1 to 5 when the program is executed by the processor.
8. A computer readable storage medium storing a computer program, characterized in that the computer program, when executed by a processor, implements the method according to any one of claims 1 to 5.
CN202310505351.7A 2023-05-08 2023-05-08 Application program data environment switching method and device, electronic equipment and medium Active CN116225576B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310505351.7A CN116225576B (en) 2023-05-08 2023-05-08 Application program data environment switching method and device, electronic equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310505351.7A CN116225576B (en) 2023-05-08 2023-05-08 Application program data environment switching method and device, electronic equipment and medium

Publications (2)

Publication Number Publication Date
CN116225576A CN116225576A (en) 2023-06-06
CN116225576B true CN116225576B (en) 2023-07-28

Family

ID=86571592

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310505351.7A Active CN116225576B (en) 2023-05-08 2023-05-08 Application program data environment switching method and device, electronic equipment and medium

Country Status (1)

Country Link
CN (1) CN116225576B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109684201A (en) * 2018-11-26 2019-04-26 平安科技(深圳)有限公司 It is switched fast the method, apparatus, computer equipment and storage medium of running environment
CN110825459A (en) * 2019-11-08 2020-02-21 深圳前海环融联易信息科技服务有限公司 Enumeration constant hot loading method and device, computer equipment and storage medium

Family Cites Families (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7263687B2 (en) * 2002-09-09 2007-08-28 Sun Microsystems, Inc. Object-oriented enumerated type facility
US7856623B2 (en) * 2006-05-05 2010-12-21 Sap Ag Method and system for providing an enumeration assistant
US20130239192A1 (en) * 2012-03-09 2013-09-12 RAPsphere, Inc. Method and apparatus for securing mobile applications
JP2015114844A (en) * 2013-12-11 2015-06-22 日本電信電話株式会社 Method, apparatus, and program for switching application execution environment
US9329844B2 (en) * 2014-05-30 2016-05-03 Apple Inc. Programming system and language for application development
CN105451258B (en) * 2014-09-26 2019-10-25 优视科技有限公司 A kind of test processing method and device
US10289409B2 (en) * 2017-03-29 2019-05-14 The Travelers Indemnity Company Systems, methods, and apparatus for migrating code to a target environment
CN109634648B (en) * 2017-10-09 2022-02-08 武汉斗鱼网络科技有限公司 Method and device for rapidly switching SDK network interface environment
CN108897692A (en) * 2018-07-06 2018-11-27 武汉斗鱼网络科技有限公司 Dynamic switching method and system, the server and storage medium of network environment
US11829801B2 (en) * 2018-11-13 2023-11-28 Vantiq, Inc. Mesh agents for distributed computing
CN109783081A (en) * 2018-12-27 2019-05-21 百富计算机技术(深圳)有限公司 A kind of development approach of application program, device and Integrated Development Tool
CN110232022A (en) * 2019-05-21 2019-09-13 深圳壹账通智能科技有限公司 Network environment test method, device and terminal device
CN110765008B (en) * 2019-10-09 2023-08-18 网宿科技股份有限公司 Data processing method and device
CN114579419A (en) * 2020-11-30 2022-06-03 中移(苏州)软件技术有限公司 Data processing method and device and storage medium
CN112597027A (en) * 2020-12-25 2021-04-02 上海高顿教育科技有限公司 Method and device suitable for APP to perform environment switching debugging
CN115576528A (en) * 2022-10-27 2023-01-06 成都赛力斯科技有限公司 Architecture method, device, storage medium and computer equipment of function control program
CN115904942A (en) * 2022-10-31 2023-04-04 北京声智科技有限公司 Method, device, equipment and medium for switching application environments of application program

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109684201A (en) * 2018-11-26 2019-04-26 平安科技(深圳)有限公司 It is switched fast the method, apparatus, computer equipment and storage medium of running environment
CN110825459A (en) * 2019-11-08 2020-02-21 深圳前海环融联易信息科技服务有限公司 Enumeration constant hot loading method and device, computer equipment and storage medium

Also Published As

Publication number Publication date
CN116225576A (en) 2023-06-06

Similar Documents

Publication Publication Date Title
US20240095043A1 (en) Execution of sub-application processes within application program
EP3493059B1 (en) Application data migration method and device
US8843895B2 (en) Debugger connection
WO2018213311A1 (en) Distributed versioning of applications using cloud-based systems
US20150154224A1 (en) Method, device, processing center and system for desktop synchronization
US8438418B2 (en) Simplifying automated software maintenance of data centers
CN113312037A (en) Data processing method, device and equipment applied to microservice and storage medium
CN110457154B (en) Abnormal service processing method and device, storage medium and communication terminal
CN112506854B (en) Page template file storage and page generation methods, devices, equipment and media
WO2019223136A1 (en) Data acquisition method and apparatus, and computer device and storage medium
CN111737137A (en) Interface test data generation method and device, host and storage medium
CN111538659B (en) Interface testing method, system, electronic equipment and storage medium of business scene
CN113268260A (en) Routing method and device for web front end
CN113641936B (en) Method, device, electronic equipment and storage medium for page skip
US8914815B2 (en) Automated framework for tracking and maintaining kernel symbol list types
CN111444453A (en) Page return data processing method and device
CN111309743A (en) Report pushing method and device
CN110574006B (en) System and method for automatically synchronizing responses and conditions on a device
CN116225576B (en) Application program data environment switching method and device, electronic equipment and medium
CN116361106A (en) Log processing method and device, electronic equipment and storage medium
CN112363707B (en) Control layer general scheduling method based on JAVA reflection technology
CN114706772A (en) Installation environment detection method, device, equipment and storage medium
CN111506499B (en) Method and device for detecting availability of parameters in applet and electronic equipment
WO2017096889A1 (en) Method and device for upgrading and downgrading system
CN114510334A (en) Class instance calling method and device, electronic equipment and automatic driving vehicle

Legal Events

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

Effective date of registration: 20240116

Address after: No. 13 Xingxiang Road, Zengjia Town, High tech Zone, Shapingba District, Chongqing, 400039

Patentee after: Chongqing Selis Phoenix Intelligent Innovation Technology Co.,Ltd.

Address before: 610095 No. 2901, floor 29, unit 1, building 1, No. 151, Tianfu Second Street, high tech Zone, China (Sichuan) pilot Free Trade Zone, Chengdu, Sichuan Province

Patentee before: Chengdu Thalys Technology Co.,Ltd.