Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iphone localStorage "QUOTA_EXCEEDED_ERR" issue

Tags:

I trying to use Client Side Storage available in HTML5 (localStorage) for Iphone Application , and I'm completely aware of the "QUOTA" associated for localStorage(which is currently 5MB).

Now the problem is for a my application (with no data previously stored) . trying to store the data in localStorage is resulting in QUOTA_EXCEEDED_ERR although the size of the overall data is way less than 5 MB (~ 4Kb to be precise ( found using chrome web inspector in normal browser) )

Can anyone Share some light on this that how a data weigh 4Kb is resulting in QUOTA_EXCEEDED_ERR when the upper limit for the same 5MB

Note that the issue is only occurring for iPhone ,all the browsers and even the iPhone Simulator doesn't prompt with QUOTA_EXCEEDED_ERR error

iPhone currently is picture is iPhone 4 .

like image 409
Viren Avatar asked Jan 31 '12 09:01

Viren


People also ask

Does localStorage work on Iphone?

localStorage works on desktop but not mobile (iOS version 12.2)

Does localStorage work in Safari?

Local storage and session storage now work in Safari 10.1 and later.

How big can localStorage be?

It is limited to about 5MB and can contain only strings. LocalStorage is not accessible from web workers or service workers. Cookies have their uses, but should not be used for storage.

How do I increase local storage in Chrome?

Edit chrome/common/extensions/api/storage. json, change the "local" QUOTA_BYTES value, and rebuild chrome.


2 Answers

Go into Settings->Safari and check to see if private browsing is on. If it is, local storage will not be able to store anything. Here's some basic code to check local storage for you:

if (!!window.localStorage) 
{
    localStorage.setItem(key, val);
};

Also, how are you setting it? Are you using localStorage.setItem(key, val), or trying localStorage(key, val)? You're problem might be coming from setting it incorrectly

like image 126
JoeCortopassi Avatar answered Sep 22 '22 02:09

JoeCortopassi


I had the same issue and JoeCortopassi is only partly right: it is caused by private browsing being enabled. The code provided in that answer does not help much though. When I tested on iPad Safari(ios5) I got

console.log(!!window.localStorage); // true

As soon as I try to set a value, I get an exception:

localStorage.setItem("test", "test") // Exception 22 is thrown

So to accurately test for local storage support, it is necessary to try and set a value in local storage, for example:

var localStorageSupported = function() {
  try {
    localStorage.setItem("test", "test");
    localStorage.removeItem("test");
    return true;
  } catch(e){
    return false;
  }
}
like image 31
wosis Avatar answered Sep 25 '22 02:09

wosis