The key is a string. You can use a literal string, or can use a string stored in a variable.
In iAd Producer, you can open the page with your text fields. Click the background for the page, then open the Inspector panel. At the bottom of the Inspector panel there is an "INTERACTION" section. Click on the "+" icon to create a new "View will Appear" event. Then select "Execute Javascript" for that event. Then click the ">" button to open the javascript code editor. If the outlet to your text field is named "textField" you could use javascript like this:
this.onViewControllerViewWillAppear = function (event) {
var theValue = this.outlets.textField;
if (localStorage.getItem("theKey") === null) {
theValue.value = "Please enter some data";
} else {
theValue.value = localStorage.getItem("theKey");
}
};
The above will restore the value in localstorage into the text field (or set it to "Please enter some data" if no value has been stored).
To set the value, click on your text field on the page. At the bottom of the Inspector panel there is an "INTERACTION" section. Click on the "+" icon to create a new "Did Change Value" event. Then select "Execute Javascript" for that event. Then click the ">" button to open the javascript code editor. This javascript will store the value in localstorage using a key named "theKey":
this.onControlValueChange = function (event) {
var theValue = this.viewController.outlets.textField;
localStorage.setItem("theKey", theValue.value);
};
The above will store any changes in localstorage using a key named "theKey".