Context:
$cookies.put()
Problem:
On Android if the user kill the application with 30 seconds after $cookies.put() is called the cookie will be gone on the next reboot.
If the user wait more than 30 seconds (like 35 seconds or more) everything works fine.
Question:
How can we force the cookie to be saved instantly (or at least much faster)?
Notes:
I had the same problem and made a small plugin (still work in progress) to fix that.
It exposes the flush method, which will apply your cookie modifications (put and remove) to persistent memory.
link to cordova-plugin-cookie-manager
Feel free to contribute.
The CookieManager design in the android makes it difficult to implement.
The webview and the cookiemanager which contain their own in_memory databases and are in sync to one another hence there is no need to sync the two of them.
The removeSessionCookie doesn't provide a callback or any way for it to complete and since this method has been implemented in the WebView classic versions.
Here are some solutions in which you can sync up between HttpUrlCookieManager and the android webkit cookie manager
Sync up link 1
Another thing to note here is when you use $cookie.put() it defines the cookies to be sent along with the rest of the HTTP headers to the client but if you use the third party api's to get the cookies it may not contain cookies only from the client anymore which may result in unwanted side effects.
You may refer to the link here as suggested by Author to this post - author' post and here is the link for the protocols to be used while defining the cookies link here
Here is another link that i stumbled upon which may help a bit
link here
or to use the same repository/database of the webview and the HttpUrlConnection you can create your own handler as implemented in the following stack thread Stack thread
Hope it may help you a bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With