开发者

Local HTML 5 database usable in Mac Dashboard wigdets?

I'm trying to use HTML 5's local database feature on a Mac Dashboard widget. I'm programming in Dashcode the following javascript:

if (window.openDatabase)
{
   database = openDatabase("MyDB", "1.0", "Sample DB", 1000);
   if (database) 
   {
        ...database code here...
   }
}

Unfortunately the database-vari开发者_Go百科able remains always null after the call to openDatabase-method. I'm starting to think that local databases are not supported in Widgets...

Any ideas?

/pom


No you will not be able to do the above. And even if you could then you would not be able to distribute the widget without distributing the database assuming it was a MySQL or SGLite. (not sure what you mean by HTML 5's local Db.

here are a number of ways round this:-

You can add a data source which can be a JSON file, or an XML file or and RSS feed. So to do this with JSON for example you would write a page on a server in PHP or something that accessed a database so that when the URL was called the result was a JSON string. Take the JSON string and parse it and use it in the Widget. This will let you get data but not save it.

Another way would be to use the user preferences. This allows you to save and retrieve data in the individual widget.

So

var preferenceKey = "key";        // replace with the key for a preference
var preferenceValue = "value";    // replace with a preference to save
// Preference code
widget.setPreferenceForKey(preferenceValue, preferenceKey);

You can then retrieve it with

var preferenceForKey = "key";    // replace with the key for a preference
// Preference code
preferenceForKey = widget.preferenceForKey(preferenceForKey);

The external call, you could also use REST will let you read any amount of data in and the preferences will let you save data for later reuse that will survive log out's and shut downs.

The Apple site has a lot of information about Widgets and tutorials as well thjat are worth working through.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜