0

I'm using iAd producer to create HTML widgets for iBooks I'm making using iBooks Author. I've done some research and learned that I can have user input saved into local storage by way of a variable that is called every time the widget is opened. This is great except for the new problem of having to create hundreds of text box widgets all with different variables so I can use these text boxes on multiple pages. Is there a way for me to automate this using Java Script? One idea I had was to use a "while" function to tell the script to ++ the variable if the one it tried to use was not empty. Example: the variable "001" was already used so the code would ideally set the next user text to variable "002". Preferably, I'd like to be able to create one widget with this code that I could reuse anywhere else.
Here is the code I'm currently using:

/*Widget code*/

this.onViewControllerViewWillAppear = function (event) {
    var theValue = this.outlets.textField;
    if (localStorage.getItem("theKey102") === null) {
        theValue.value = "";
    } else {
        theValue.value = localStorage.getItem("theKey102");
    }
};

/*This is the code for one of the text boxes I'm using */

this.onControlValueChange = function (event) {
    var theValue = this.viewController.outlets.textField;
    localStorage.setItem("theKey102", theValue.value);
};
Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
  • Just a heads up, on January 15, 2016 [Apple announced](https://developer.apple.com/news/?id=01152016a) that the iAd App Network will be discontinued. iAd is scheduled to be discontinued on June 30, 2016 and is no longer accepting new apps into the network. – Daniel Storm Mar 22 '16 at 19:22
  • Daniel, thanks for the reply. I did hear about the iAd shutdown. I'm hoping Apple chooses to continue to support iBooks Widget development via another app. Only time will tell. My post is still relevant however. I've found an alternative and it works in much the same way as iAd Producer when it comes to Widget developing. – Steven Wingrove Mar 24 '16 at 05:45

0 Answers0