Cordova iOS localStorage old values - javascript

Each time appp is opened, user recieves data in Ajax request, it is stored in browser localStorage, and when user next time opens app, it shows localStorage values from the very first time they were set. Seems like after initially setting localStorage items, they won't change. They work fine during app, but when opening it again, there still are the very first values.
App is built on iOS and Android using Cordova latest version (as of current), using jQuery Ajax requests and browser localStorage.
Example:
User opens app for first time.
Access token is requested and is saved in localStorage localStorage.setItem('token', '1234');
User uses app for some time and exits.
Next time user is opening app and gets token, it is again saved in localStorage localStorage.setItem('token', 'abcd');
User uses app, then quits.
Again opening app and checking localStorage, the stored access token is 1234 from the first time.

iOS considers any data stored inside the Webview of an app (HTML5 Local Storage, WebSQL, IndexedDB, Cookies, etc.) be temporary/cache data.
Therefore, if an iOS device starts to run low on space, iOS may decide to wipe the Webview data to recover space.
When this happens, the app name on the Home screen changes to "Cleaning..." and when you next launch your app, all your Webview data is gone.
For this reason, I moved from storing data inside the Webview of Cordova apps to storing it in a native SQLite database using the cordova-sqlite-storage plugin.
The native DB file is considered "proper" data by iOS so is not wiped when an iOS device runs low on storage space.
I empirically tested both scenarios by filling an iPad with movies until it was running low on space, triggering iOS to start its "cleaning" of installed apps.
For more info, see this related issue.

Related

How can I share data between an installed PWA and a Safari PWA on iOS?

When the user starts my PWA from the iOS start screen (installed PWA) it accesses one instance of storage (IndexedDB, cookies, etc). When he starts the same PWA through Safari it accesses a different storage instance. It is very inconvenient, because from the user perspective he opens the same app, but he doesn't see the same data.
How can I make sure each PWA's data storage is updated when the other makes a change?
To make things more complicated, I can't rely on having an internet connection, so I can't sync my data with a server. And I can't force the user to only start the PWA from the start screen. And I can't use the new File System Access API, because it will annoy the user with file access prompts.

Cookies disappear from a PWA each time a user restarts their phone

I have a web app that uses a cookie as an access token (to let users stay logged in after refreshing/closing the site/app). It works perfectly on desktop but when I try to use it on my Android phone (installing it via Chrome), for some reason it says that I'm not logged in which means it wasn't able to load the access token.
Why is this happening? Is there a difference between how cookies are handled in the browser and when starting a PWA as a standalone?
Also two little side questions, 1, is there a way to debug a PWA that's added to the homescreen (using some sort of remote debugger) and 2, would it be a security risk to use localStorage for storing the access token instead of a cookie? I realize neither is particularly safe but I read that cookies are slightly better for this sort of thing. localStorage works just fine when starting as a standalone

Local Storage - Phone out of space

I have used the Ionic framework to build my App and have been thinking about the local storage and how it works. One of my users phone storage is capped out with photos and video content, and I was wondering how this would effect an HTML5 App that uses local storage.
I decided to test it by purchasing a cheap phone with only 2GB internal storage, and filling it up with random Audio files from my PC. I have managed to get Windows to think there is 0kb left in internal storage, yet my Ionic App can still add data to local storage.
Does anyone know why this is, or have any input as to where local storage actually is saved? I sort of expected it to just store in the browsers App Data, but maybe it is somewhere else?
EDIT
Have just looked at the phone storage and it says there is still 99.9mb that is un-used. Android must not let Windows fill all of the device's storage. Does anyone still have any knowledge on what would happen if I managed to fill this last 99mb??
OK.. I cleared my App data and then managed to fill up the last 99mb of space by duplicating more files using the File Commander App on the phone.
I then opened my Ionic App and logged in (which downloads about 1.5mb of App data) and the App seemed to work fine (as everything was stored in RAM at the time). Once the App closed and I re-opened it, all the stored data was gone (as there was no space to move it to from RAM I am guessing)
End result: App works fine in RAM but if there is no space in localStorage, it will not error or tell you it didn't work, it will just not save the data.
Note: I have not tested this when there has been existing data in App, and trying to add to it which would take the phone over the storage limit. Im unsure if this would corrupt the existing data or just not let you add to it.

Can you detect if your web page is running inside your Windows Mobile native App?

How can you check that a web page is being served under a native app on Windows phone?
You cant use custom user agents, so to date we have done the following...
Check the user agent for Windows Phone, check it for WebBrowser which indicates its served from the WebBrowser windows control, and then try to call a method in our native app to guarantee we are in our app.
However, the latest browser updates to windows have removed WebBrowser from the user agent.
This means there would be delay when viewing the page on Mobile IE, as we would have to try to talk to our native app to see if it's there or not, and wait for a timeout to assume its not there.
So..
1) Is there anyway now to set custom user agents in windows Mobile - everything we have tried to date has failed.
2) Is there another way we can indicate to the page that its running in our app? Inject some JS at the start some how?
3) Any other way to somehow tell the web page what its running in? Cookies, local storage?
We need to know where its running before it has finished loading, so JS scripts can tell where they are running as they load up.
m

Does localStorage in Javascript get wiped off after clearing browser history

I have a little question.
Does localStorage get wiped off once the user clears the bowser history?
If yes, then is there a way that I can save a URL as a string on the mobile device somewhere which always stays there even if the user or any other application forces the browser history to be cleared.
And I can go get that string(URL) whenever I need it for my mobile app.
The thing is I want to save URL of a restful service which fetches updates to the mobile client. I want that whenever a user launches my mobile app for the first time only he should manually key-in that URL (that will be provided by me) to get the updates and then some how I use some JavaScript API to save that URL on mobile device(which user is never ever able to delete even if the browser history is deleted anyway)so that on every subsequent launch the user needs not to key-in that URL again for the updates and if the updates exit mobile app should automatically be able to get that saved URL and contact the service to fetch the updates.
Thanks.
Does localStorage get wiped off once the user clears the bowser history?
Yes localstorage does get cleared when browser data is removed.
Save a URL as a string on the mobile device somewhere which always stays there even if the user or any other application forces the browser history to be cleared.
Are you refering to an actual mobile app or a website in a browser on a phone? If its a website within the browser then the answer is no.
If you are referring to an actual mobile app then there are several method to store data. You might want to expand you question if this is the case.

Categories

Resources