I am trying to remove cookie using $.removeCookie() in my phonegap application, but it removes the NativeStorage (using the plugin cordova-plugin-native-storage) in my android.
The same problem repeats in IOS. But in IOS NativeStorage gets cleared once app is closed (even if I don't clear the cookie).
FYI : I am storing my login access token and few more details in cookies.
Any suggestion to keep the data to retain even if cookie is cleared?
Related
I have implemented WASLTPAAuthentication (with WASLTPALoginModule and Realm) and it works well.
I can call my JAX-RS and they took the identity by the cookie.
My problem is: after I tap the Home button and open the menu of recent applications to swipe and quit the application, then once I open it again the session is destroyed and the cookie is lost and I need to insert my credentials and login again.
Is there a way to prevent this? Do I need to store the cookie on the localStorage in some way?
It looks like even though your LTPA cookie is still valid, when you close the application and the session dies, the cookies are being cleared. You will need to save the LTPA cookie in local storage and then set the cookie manually if you want it to use it for multiple sessions.
The LTPA cookie is included in the attributes object of the UserIdentity returned after successfully logging into the WASLTPARealm, so you should already have access to it. Its just a matter of saving and retrieving it.
(I'm asking this partly for learning purposes, I realize what I'm trying to do might be entirely wrong!)
I have a php file on my website that handles log in and sets a cookie for the user if log in is successful. if setcookie() fails, I error out instead of displaying the rest of the page.
When I try to access this page using my android app (which uses HttpURLConnection with POST), the setcookie() fails. I'm guessing this is because the client isn't a browser and can't handle cookies.
so first of all, is there away for my app to be able to receive cookies from the server and store them? if not, how do you handle maintaining a login session with the user so you dont have to send a username and password, every time you want to access data from the server?
THanks
A couple of notes before the workaround:
The function is called setcookie() not set_cookie()
Android browsers do support cookies afaik, so you probably should look into this further. Perhaps the format of your setcookie call is not valid?
If you can't use cookies, then the workaround is to simulate your own session mechanism by passing your cookie value as a url parameter on every request.
I'm developing an app with PhoneGap 2.2.0 and Jquery Mobile 1.2. I need the app to read a file and call a server for data before the user sees the screens. What event should I use in order to get it working? I tried mobile init and deviceready and and it didn't work well.
Assuming you are just talking about the first page here, you don't need to do anything before the page renders - just turn off AutoHideSplashScreen and hide it manually when the custom rendering is done.
I use that approach for loading the first page of the app from a database, but I wouldn't recommend it for a server connection - basically the app will crash if you are not connected, and therefore not be able to pass the app store review.
So that the connection isn't required, I render the view with locally stored data first - either a default set in the app javascript or a saved copy of the last successful call. Then the ajax call runs in the background and the view can be updated when it finishes.
I have an app need login, I use a singleton http client to do everything, so it can track the cookies for me.
But when I launch a browser intent in my app to view some html pages, the app sometimes be killed by low memory, when user come back from the browser, my app activity would be recreated, but the new http client would not contains that login session id.
So I think what I need is to cache the cookies when my app get killed, and then restore it back when the app got recreated. I know there is a CookieSyncManager, but I do not have a full picture of how to use that.
(1) So How can I do that? is Cookie seralizable, I just thought to cache it in the sdcard, maybe a bad idea.
Another more general question maybe:
(2) How to share httpclient with webview/system browser? Not just pass cookies from httpclient to webiew/browser, but also get the cookies when initialize the cookies, How to make the http client and webview/browser share just ONE copy of cookie store in any time?
Use SharedPreferences to store cookies as string.
Take a look at this; http://developer.android.com/reference/android/app/Activity.html#SavingPersistentState
Also android developers use parcelable class, rather than serializable class. I think the reason is performance issues # mobile devices...
I am working on a web application for android phones, which is basically few js and html files packaged using Phonegap for android. I am making http requests to the server, getting some cookies (whose life is 10 yrs). These cookies are set by the response header. Now this works fine for this session, the set cookies are sent with each request. But if a quit the app and restart it, the cookies vanish, and are not sent with the request.
The life of the cookies is 10 yrs. Shouldnt they persist? Please tell me where i am getting it wrong?
EDIT-- I tried saving the cookie in an sqlite db, and then setting it properly in document.cookie before making the ajax call. Still its not being sent. Any ideas...?
Cookies wont persist after the app is closed. Also you cannot directly set the cookies in an xhr object using javascript, according to w3c specifications, so thats why i wasnt able to do that. the solution would be to re-perform the actions which set the cookies in the cookie jar in the first place.