Thursday, September 12, 2013

Using LocalStorage with Cydgets

If I ask a user for information, I don't want to have to keep asking them.

With Cydgets when you unlock your phone everything resets. Just as if you closed your browser.

Recently i've been using jQuery Cookies, although very frustrating. They worked very well. Which gave me the ability to create amazing things.

Well through my experiments with Cydgets. I finally maxed out my cookies. I needed to return the binary for an image. Which was over 100,000 characters:P So I needed a replacement.

I tried LocalStorage before, but with most doesnt work with winterboard. Reason I chose cookies. (My workaround so to speak)

Gave LocalStorage another shot, and works perfectly. I will explain.

var locale = "32118";

Here is a location code for a weather widget. We need to save it so it doesn't reset.

Make a variable 

var locale = prompt("Enter your ZipCode", "");

save it to LocalStorage

localStorage.setItem('nameoffile', locale);

how to get the file

var getitems = localStorage.getItem("nameoffile");

You can either alert(getitems); console.log or set it to variable

Now we need var locale to be dynamic. We cannot have it just a prompt.

For example.    if(getitems != null){
var locale =getitems;
}

If get items is not empty, then var locale is equal to getitems, which is your LocalStorage
Below its saying if the getitems is empty then show a prompt, then save to localstorage.

else{
var locale = prompt("Enter your ZipCode", "");
localStorage.setItem('nameoffile', locale);
}

No comments:

Post a Comment