A cookie management method and device based on iOS system
By reading and comparing browser cookie information in iOS sandbox, the problem of cookie information out of synchronization between WKWebview and NSHTTPCookieStorage is solved, and the cookie is persistently saved, ensuring that the user login information can still be used after the browser restarts.
Patent Information
- Application Number
- CN202111675825.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-31
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2041-12-31
AI Technical Summary
The WKWebview in the iOS system is not synchronized with the cookie information of NSHTTPCookieStorage, resulting in the user's login information being unable to be saved, and the user needs to log in again.
By reading and comparing browser cookie information in iOS sandbox, modifying and saving sandbox cookies, ensuring that cookies can still be used after the browser is restarted.
The persistent saving of cookies is realized, and the user login information can still be maintained after the browser is restarted, which solves the problem that WKWebview cannot save cookies.
Smart Images

Figure CN114282147B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of browser information management, and in particular relates to a cookie management method and device based on an iOS system. Background Art
[0002] Most existing Web applications use the HTTP protocol to transmit data. The HTTP protocol is a stateless protocol. When the data exchange is completed, the connection between the client and the server will be closed, and a new connection needs to be established when accessing again. The current cookie mechanism generates cookie data on the terminal device and stores it locally when the terminal device accesses the website through the browser. When the terminal device requests page information again, it can carry the cookie data, so that the server generates page information based on the cookie information. Currently, many H5 businesses rely on cookies as login status verification.
[0003] However, for the iOS system, there are defects in cookie sharing and management: the cookie information of the browser WKWebview and NSHTTPCookieStorage is not synchronized. This is because the WKProcessPool instance will be reset after the application is restarted. When entering WKWebview again, the cookies will be lost and the user information cannot be saved. For example, after a user opens a login interface in WKWebview and fills in the information to log in, the login information is not saved when entering the interface again, and the user needs to log in again. Summary of the invention
[0004] Based on this, the present invention aims to propose a cookie management method and device based on the iOS system to overcome the defects of the prior art.
[0005] In a first aspect, the present invention provides a cookie management method based on an iOS system, the method being executed at a cookie manager, comprising:
[0006] Receive the URL sent by the browser;
[0007] Sending a sandbox cookie reading instruction to the iOS sandbox according to the URL domain name, where the sandbox cookie reading instruction at least includes the URL domain name for the iOS sandbox to identify the storage path;
[0008] Determine the sandbox cookie based on the sandbox cookie response information returned by the iOS sandbox;
[0009] Read the current cookie after the browser jumps to the URL;
[0010] Compare the sandbox cookie with the current cookie and modify the sandbox cookie based on the difference between the two;
[0011] Returns the modified sandbox cookie to the iOS sandbox for storage.
[0012] Further, modifying the sandbox cookie includes:
[0013] If the fields and paths of the current cookie do not exist in the sandbox cookie, the information of the current cookie is added to the sandbox cookie.
[0014] Further, modifying the sandbox cookie includes:
[0015] When the values and paths of the current cookie and the sandbox cookie are inconsistent but the fields are consistent, the current cookie is replaced with the sandbox cookie.
[0016] Further, according to the sandbox cookie response information returned by the iOS sandbox, it is determined that the sandbox cookie includes:
[0017] When the response message indicates that the cookie file is not empty, the cookie file is read as a sandbox cookie and set to the browser;
[0018] When the response message indicates that the cookie file is empty, the cookie file of the current browser is read and sent to the iOS sandbox for saving as a sandbox cookie.
[0019] Furthermore, when the received cookie file is not empty, the expiration time and path of the cookie are queried. When the cookie file is not expired and the path is correct, it is read as a sandbox cookie and set to the browser.
[0020] In a second aspect, the present invention provides a cookie management method based on an iOS system, the method being executed at an iOS sandbox, comprising:
[0021] Receive a sandbox cookie read instruction from a cookie manager, wherein the read instruction includes at least a URL domain name;
[0022] Returns a sandbox cookie response message corresponding to the URL domain name;
[0023] Receive the modified sandbox cookie returned by the cookie manager, where the modified sandbox cookie is modified by the cookie manager by comparing the sandbox cookie with the current cookie;
[0024] Save the modified sandbox cookie to the storage path corresponding to the URL domain name.
[0025] Further, when the cookie file does not exist in the sandbox cookie response message, the method includes:
[0026] Receive the cookie file returned by the cookie manager and save it as a sandbox cookie.
[0027] In a third aspect, the present invention provides a cookie management system based on the iOS system, which at least includes:
[0028] WKWebview browser, used to provide the current browser cookie to the cookie management unit, and / or receive the sandbox cookie sent by the cookie management unit;
[0029] A cookie management unit, in which a cookie management program is running. When the program is executed, the system executes the iOS system-based cookie management method provided by the first aspect of the present invention;
[0030] An iOS sandbox storage unit, in which a sandbox directory of an application is stored, is used to execute the iOS system-based cookie management method provided by the second aspect of the present invention.
[0031] In a fourth aspect, the present invention provides a cookie management device based on the iOS system, comprising a memory storing computer executable instructions and a processor, wherein when the computer executable instructions are executed by the processor, the system executes the cookie management method based on the iOS system provided in the first and second aspects.
[0032] The present invention also provides a readable storage medium storing a computer executable program, which, when executed, can implement the iOS system-based cookie management method provided in the first aspect and the second aspect.
[0033] It can be seen from the above technical solutions that the present invention has the following advantages:
[0034] The present invention provides a cookie management method and device based on the iOS system, wherein the method reads the cookie of the WKWebview browser and saves it to a sandbox. When the WKWebview browser is opened again, the cookie is read from the sandbox and reset to the browser, so as to achieve the purpose of not losing the cookie. Compared with the prior art, the present invention saves the cookie to a file in the sandbox. When the browser opens a URL or jumps to a URL, the cookie data file corresponding to the local iOS sandbox is updated. When the App exits and restarts, the cookie file of the sandbox will not be lost and can be used permanently until the cookie expires, which can well solve the problem that the WKWebview in the existing iOS system cannot save cookies. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0036] Figure 1 An iOS-based cookie management system architecture diagram provided by an embodiment of the present invention
[0037] Figure 2 Flowchart of a cookie management method based on iOS system provided by an embodiment of the present invention
[0038] Figure 3 Flowchart of a cookie management method based on iOS system provided by another embodiment of the present invention
[0039] Figure 4 Flowchart of a cookie management method based on iOS system provided by another embodiment of the present invention
[0040] Figure 5a Schematic diagram of cookie content after accessing a website link and logging in in one embodiment of the present invention
[0041] Figure 5b Schematic diagram of cookie content of re-entering a website link when a cookie manager is not used in an embodiment of the present invention
[0042] Figure 5c Schematic diagram of cookie content of re-entering a website link when using a cookie manager in one embodiment of the present invention
[0043] Figure 6Schematic diagram of the H5 interface accessed in one embodiment of the present invention
[0044] Figure 7a Schematic diagram of cookie content after accessing the H5 interface and filling in information in one embodiment of the present invention
[0045] Figure 7b Schematic diagram of re-accessing H5 interface cookie content when the cookie manager is not used in one embodiment of the present invention
[0046] Figure 7c Schematic diagram of revisiting H5 interface cookie content when using a cookie manager in one embodiment of the present invention
[0047] Figure 8 Schematic diagram of the structure of a cookie management device based on the iOS system provided by an embodiment of the present invention DETAILED DESCRIPTION
[0048] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0049] Embodiment 1
[0050] See also Figure 1 The present invention provides a cookie management system based on the iOS system. In this embodiment, exemplary descriptions of other components are also provided. The whole system includes the following parts:
[0051] WKWebview browser, used to provide the current browser cookie to the cookie management unit, and / or receive the sandbox cookie sent by the cookie management unit.
[0052] The cookie management unit runs a cookie management program for communicating and interacting with the WKWebview browser and the iOS sandbox storage unit. When receiving the URL of the browser, the cookie file is communicated with the iOS sandbox storage unit according to the URL domain name, and the sandbox cookie is compared with the current cookie. The sandbox cookie is modified according to the difference between the two, so that the new cookie file generated by each browser opening or adjusting the URL can be updated to the iOS sandbox. When the user re-enters the application, the cookie file will not be lost, and the user's last login information and other user information will be retained.
[0053] The iOS sandbox storage unit stores the sandbox directory of the application program, and is used to store cookie files that interact with the cookie management unit, so that the cookie files can be carried each time the user enters the application, retaining the user information previously in the same path.
[0054] It is easy to understand that the above components and / or units can be implemented by software codes. In this case, the above components and / or units can be stored in a memory arranged at a control terminal such as a control computer.
[0055] The cookie management system provided in this embodiment introduces a cookie management unit based on the characteristics of cookie management of the WKWebview browser in the iOS system, reads the cookies generated by the browser and the cookies retained in the sandbox, compares the two and modifies or replaces the cookie file according to the difference information, so that the cookies will not be lost when the user enters the application again, which can well solve the problem that WKWebview cannot save cookies in the existing iOS system.
[0056] Embodiment 2
[0057] See also Figure 2 The interaction sequence diagram shown is based on the cookie management system based on the iOS system provided in the first embodiment. This embodiment provides a cookie management method based on the iOS system from the cookie manager side, including:
[0058] Receive the URL sent by the browser;
[0059] Send a sandbox cookie read instruction to the iOS sandbox according to the URL domain name, and determine the sandbox cookie according to the information returned by the iOS sandbox;
[0060] Read the current cookie after the browser jumps to the URL;
[0061] Compare the sandbox cookie with the current cookie and modify the sandbox cookie based on the difference between the two;
[0062] Returns the modified sandbox cookie to the iOS sandbox for storage.
[0063] In some embodiments, before modifying the sandbox cookie, it is necessary to determine the consistency between the fields of the current cookie and the sandbox cookie. If the fields and paths do not exist in the sandbox cookie, the information of the current cookie is added to the sandbox cookie; if the fields are consistent, but the values and paths are inconsistent, the current cookie is replaced with the sandbox cookie.
[0064] In some embodiments, a sandbox cookie read instruction is sent to a sandbox directory with a path named by the domain name in the iOS sandbox according to the URL domain name;
[0065] If the received cookie file is not empty, it is read as a sandbox cookie and set to the browser;
[0066] When the received cookie file is empty, read the cookie file of the current browser and send it to the iOS sandbox for it to be saved as a sandbox cookie.
[0067] Before reading the cookie file and setting it to the browser, you need to determine the cookie expiration time and path. If the cookie file has not expired and the path is correct, it will be read as a sandbox cookie and set to the browser. Otherwise, the cookie file will not be set.
[0068] Embodiment 3
[0069] This embodiment further describes the cookie setting completed by the interaction between the cookie manager and the iOS sandbox.
[0070] (1) When a cookie file is stored in the sandbox, the interaction of the cookie management execution process is as follows Figure 3 shown.
[0071] Before the WKWebview browser opens the URL, it passes the URL to the cookie manager.
[0072] The cookie manager analyzes the URL to obtain the domain name, and reads the cookie data file named after the domain name in the sandbox based on the domain name.
[0073] Since the sandbox stores the cookie file stored in the last user visit, you can directly read the cookie file to determine the cookie expiration time and cookie path. If the cookie has not expired and the path is correct, set the cookie to the WKWebview browser.
[0074] After the WKWebview browser redirects to the URL, the cookie manager reads the current cookie file of the WKWebview browser.
[0075] Compare the previously read sandbox cookie with the current cookie, and modify the sandbox cookie according to the difference information between the two. This embodiment mainly compares the fields, paths and values of the two. If the fields and paths do not exist in the sandbox cookie, the information of the current cookie is added to the sandbox cookie; if the fields are consistent, but the values and paths are inconsistent, the current cookie is replaced with the sandbox cookie.
[0076] (2) When no cookie files are stored in the sandbox, the interaction of the cookie management execution process is as follows Figure 4 shown.
[0077] Before the WKWebview browser opens the URL, it passes the URL to the cookie manager.
[0078] The cookie manager analyzes the URL to obtain the domain name, and reads the cookie data file named after the domain name in the sandbox based on the domain name.
[0079] Since the sandbox does not store the cookie file stored by the last user visit, for example, when the user logs in to a web page for the first time, the cookie file generated by the current web page is read, a new storage path is created under the sandbox directory of the same application, and the currently read cookie file is saved to the newly created storage path as a sandbox cookie.
[0080] The subsequent interactions are the same or similar to those in situation (1) and will not be described in detail here.
[0081] To further illustrate the interaction process, take visiting www.baidu.com as an example.
[0082] When the user visits the webpage in the WKWebview browser, the cookie manager queries the iOS system / var / mobile / Containers / Data / Application / in the sandbox directory / Documents to see if there is a file named baidu.com. If the file exists, read the cookie content in the path / var / mobile / Containers / Data / Application / Documents and set it to the current browser. If the file does not exist, create a file named baidu.com in the path / var / mobile / Containers / Data / Application / Documents and save the cookie content of the current browser to that path.
[0083] When the user clicks "Tieba" on the web page to jump to the URL tieba.baidu.com, the cookie manager will read the current cookie. Since the host of the web page tieba.baidu.com is baidu.com, the manager will read the cookie content under the path / var / mobile / Containers / Data / Application / Documents / baidu.com, compare the cookie content read in the sandbox with the cookie of the current browser, and compare the fields, paths and values of the two one by one.
[0084] If the cookie fields and path of the URL tieba.baidu.com are not stored in the cookie under / var / mobile / Containers / Data / Application / Documents / baidu.com, the current cookie information is added to the sandbox cookie; if the fields of the two are consistent but the values and paths are different, the cookie content of the URL tieba.baidu.com is replaced to the path / var / mobile / Containers / Data / Application / Documents / baidu.com as the sandbox cookie.
[0085] Embodiment 4
[0086] In order to illustrate the effect of introducing the cookie manager in the present invention, the access to the website http: / / easybug.org / Project / ProjectList is taken as an example for explanation.
[0087] After the user logs in to the URL using WKWebview, the cookie content stored in the corresponding cookie storage path is as follows Figure 5a As shown, after the user logs in, the cookie content adds several new data fields: rememberMe, TeamID, UserID, UserName, and UserNickName.
[0088] Before the introduction of the cookie manager, if the user exits the app and reopens the URL link, WKWebview does not save the user's previous login information. The cookie content carried is as follows Figure 5bAs shown, the aforementioned newly added data fields are not saved, and the user needs to re-enter the relevant information to log in again. This is caused by the WKProcessPool instance being reset after the application process is restarted, resulting in the loss of cookie and session cookie data in WKProcessPool.
[0089] After the cookie manager in the method proposed in the present invention is introduced, when the user enters the APP process again after logging in for the first time, the cookie manager restores the cookies stored by the previous user login to WKWebview. The cookie content is as follows: Figure 5c As shown, the user does not need to log in again.
[0090] Embodiment 5
[0091] In order to further illustrate the effect of introducing the cookie manager in the present invention, accessing the H5 service is taken as an example for explanation.
[0092] The user uses WKWebview to open an exemplary H5 interface (such as Figure 6 When the user completes the information, the cookie content is updated as shown below. Figure 7a As shown, several data fields such as currCity, currDistrict, currDoor, currProvince, currStreet, dept1, and dept2 have been added.
[0093] Before the introduction of the cookie manager, if the user exits the application and reopens the H5 interface, WKWebview does not save the user's previous filled-in information. The cookie content carried is as follows Figure 7b As shown, the aforementioned newly added data fields have not been saved and the user needs to fill them in again.
[0094] After the cookie manager in the method proposed in the present invention is introduced, when the user enters the APP process again after logging in for the first time, the cookie manager restores the cookies stored by the previous user to WKWebview. The cookie content is as follows: Figure 7c Users do not need to fill in the form again.
[0095] The above-described exemplary embodiments are merely provided to illustrate the present invention, but are not intended to be limiting.
[0096] The iOS-based cookie management method provided in the embodiment of the present application can be executed by an iOS-based cookie management device, which can be a server, a computer, a cloud, etc. Figure 8The hardware structure block diagram of the device is shown, including: at least one processor 1, at least one communication interface 2, at least one memory 3 and at least one communication bus 4;
[0097] In the embodiment of the present application, the number of the processor 1, the communication interface 2, the memory 3, and the communication bus 4 is at least one, and the processor 1, the communication interface 2, and the memory 3 communicate with each other through the communication bus 4;
[0098] The processor 1 may be a central processing unit CPU, or an application-specific integrated circuit ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present invention, etc.;
[0099] The memory 3 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory;
[0100] Among them, the memory stores computer executable instructions, and the processor can call the program stored in the memory, and the program is used to: implement the cookie management process based on the iOS system provided by the aforementioned embodiments.
[0101] An embodiment of the present application also provides a storage medium storing a computer executable program, which, when executed, can implement the iOS system-based cookie management method provided in the aforementioned embodiments.
[0102] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A cookie management method based on iOS system, characterized in that: The method is executed at the cookie manager and includes: Receive the URL sent by the browser; Sending a sandbox cookie reading instruction to the iOS sandbox according to the URL domain name, wherein the sandbox cookie reading instruction at least includes the URL domain name, so that the iOS sandbox can identify the storage path; Determine the sandbox cookie based on the sandbox cookie response message returned by the iOS sandbox; Read the current cookie after the browser jumps to the URL; Compare the sandbox cookie with the current cookie and modify the sandbox cookie based on the difference between the two; Returns the modified sandbox cookie to the iOS sandbox for storage.
2. The cookie management method based on iOS system according to claim 1 is characterized in that: The modification of the sandbox cookie includes: When the fields and paths of the current cookie do not exist in the sandbox cookie, the information of the current cookie is added to the sandbox cookie.
3. The cookie management method based on iOS system according to claim 1 is characterized in that: The modification of the sandbox cookie includes: When the values and paths of the current cookie and the sandbox cookie are inconsistent but the fields are consistent, the current cookie is replaced with the sandbox cookie.
4. The cookie management method based on iOS system according to claim 1, characterized in that: Determining the sandbox cookie according to the sandbox cookie response message returned by the iOS sandbox includes: When the response message indicates that the cookie file is not empty, the cookie file is read as a sandbox cookie and set to the browser; When the response message indicates that the cookie file is empty, the cookie file of the current browser is read and sent to the iOS sandbox for saving as a sandbox cookie.
5. The cookie management method based on iOS system according to claim 4 is characterized in that: The step of reading the cookie file as a sandbox cookie and setting it to the browser comprises: The expiration time and path of the cookie file are queried, and if the cookie file has not expired and the path is correct, it is read as a sandbox cookie and set to the browser.
6. A cookie management method based on iOS system, characterized in that: The method is executed at the iOS sandbox and includes: Receive a sandbox cookie read instruction from a cookie manager, wherein the read instruction includes at least a URL domain name; Returns a sandbox cookie response message corresponding to the URL domain name; Receive the modified sandbox cookie returned by the cookie manager, where the modified sandbox cookie is modified by the cookie manager by comparing the sandbox cookie with the current cookie; The modified sandbox cookie is saved to the storage path corresponding to the URL domain name.
7. The cookie management method based on iOS system according to claim 6 is characterized in that: When there is no cookie file in the sandbox cookie response message, the method includes: Receive the cookie file returned by the cookie manager and save it as a sandbox cookie.
8. A cookie management system based on iOS system, characterized in that: The system comprises at least: WKWebview browser, used to provide the current browser cookie to the cookie management unit, and / or receive the sandbox cookie sent by the cookie management unit; A cookie management unit, in which a cookie management program is running. When the program is executed, the system executes the iOS system-based cookie management method as described in any one of claims 1 to 5; An iOS sandbox storage unit, which stores a sandbox directory of an application, is used to execute the iOS system-based cookie management method as described in any one of claims 6-7.
9. A cookie management device based on iOS system, comprising a memory storing computer executable instructions and a processor, characterized in that: When the computer executable instructions are executed by the processor, the system executes the iOS system-based cookie management method as described in any one of claims 1-7.
10. A readable storage medium storing a computer executable program, characterized in that: When the program is executed, the iOS system-based cookie management method as described in any one of claims 1 to 7 can be implemented.
