Skip to content Skip to sidebar Skip to footer

Iphone Localstorage "quota_exceeded_err" Issue

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 currentl

Solution 1:

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

Solution 2:

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");
    returntrue;
  } catch(e){
    returnfalse;
  }
}

Solution 3:

The fact is that using private browsing mode on Safari for iOS < 6 does not empty window.localStorage and window.sessionStorage and therefore checking !!window.localStorage or !!window.sessionStorage won't be enough, and whatever you call from those components will just fail, throwing this QUOTA_EXCEEDED_ERR error.

On those platforms, the private mode seems to set the quota to zero. That's the reason why, to really test those features, the same way Modernizr does, you'll have to wrap it inside a try...catch statement.

Modernizr code :

var mod = 'modernizr';
/*...*/
tests['localstorage'] = function() {
    try {
        localStorage.setItem(mod, mod);
        localStorage.removeItem(mod);
        returntrue;
    } catch(e) {
        returnfalse;
    }
};

We have to trust web APIs, but quite carefully.

Solution 4:

Try deleting the value before setting a new one:

localStorage.removeItem(key);
localStorage.setItem(key, val);

See also this question, as it looks similar.

Solution 5:

Local storage quota is tied to domain, if you have other pages that use the data storage they may fill it up. Iterate the keys to find out whats there in the storage when you get the exception.

try {
   // try to insert storage here
} catch ( err ) {
   for ( var i =0; i < storage.length ; i++ ) {
       console.log ( storage.key( i ) )
    }
}

Post a Comment for "Iphone Localstorage "quota_exceeded_err" Issue"