www.webOShelp.net

Get the latest on:webOS Developers' RSS FeedwebOS Facebook page webOS Twitter Feed

Home Getting Started with webOS From the webcast: Local Storage, Notifications and Services

From the webcast: Local Storage, Notifications and Services

After successfully building a webOS application in the tutorial section of the webcast, Mitch Allen proceeded to uncover a few details about support for local storage, banner notifications, and services in webOS.

Local Storage

There will be three types of local storage available to applications in webOS:

  • The HTML5 Database API
  • Depot: A Mojo wrapper around the HTML5 database API. It will include basic functions to create and open databases and get and store simple objects. It's designed to simplify things for people not interested in "getting their hands dirty" in the full API. A few sample function calls were provided:

Create/Open Depot

var db= new Mojo.Depot ({name:”myDB”,version:1,replace:false}, this.openOK, this.openFail);

Save

db.simpleAdd(“myAdd”,myDataContents,this.savedListOK,this.savedListFailed);

Get

db.simpleGet(“myData”,this.getListOK,this.getListFailed);
  • Cookies function: Allows the storage of small amounts of persistent data for things like application preferences, versions, etc. Provides quick access to small amounts of data.

Banner Notifications

This simple example of a banner notification containing a text string and an icon was provided:

var msg = “Hello World!”;
Mojo.Controller.getAppController().showBanner({icon: “Img.png”,messageText: msg},msg);

Note that most functions involve passing in JSON objects as parameters. In case you're not familiar with JSON, we'll try to get a JSON tutorial up soon.

Services

There are a wide variety of services available in webOS including launching other applications (e.g. launching browser for web page, a photos application), device services such as the GPS or accelerometer, and cloud or web services. All services work in "fairly similar ways", using the servceRequest method of the controller:

Service Call

this.controller.serviceRequest (‘palm://com.palm.location’, {
   method:”getFix”,
   parameters:{
      mode:”auto”
   },
   onSuccess: this.gotFix,
   onFailure: this.error
   }
});

In this example, we're identifying the service (in this case, the location serivce), calling a method associated with the service (getFix), and passing parameters to the service (which vary depending on the service and the method being called). Because these are asynchronous events, we need to set up callbacks to receive the data (or failure information) that comes back from the getFix request.

Callback

this.gotFix=function(response){
   Mojo.Log.info(“Fix received:”, response.longitude, response.latitude);
}
this.error=function(response){
   Mojo.Log.info(response.errorText);
}

This was a great start, but we can't wait for the next webcast. Hopefully Palm doesn't decide to reveal everything to us in tiny bite-sized pieces like this.

If you're still itching for more, why not check out the other tutorials?

 

2 Comments

Feed
  1. Palm states that the Mojo application framework is "based on the HTML5, CSS and JavaScript standards that web developers already know and love"MB3-529. By building our skills with these technologies now, we can get a jump start on Mojo the moment it's released.
  2. Palm states that the Mojo application framework is "based on the HTML5, CSS and JavaScript standards that web developers already know and love". By building our skills with these technologies now, we can get a jump start on Mojo the moment it's released.

Add Comment


    • >:o
    • :-[
    • :'(
    • :-(
    • :-D
    • :-*
    • :-)
    • :P
    • :\
    • 8-)
    • ;-)