Store data in FirefoxOS

一个人想着一个人 提交于 2019-12-22 04:43:31

问题


I'm trying to do some FirefoxOS apps, but I have not seen any easy way to store local data. I hear about IndexedDB, but it seems too complex. Is there any other alternative? If not, is there any easy tutorial about it?

I have considered to store and recove remote data (doing a croos domain request), but I'm having some issues with the permissions. Is there any tutorial about XHR for FirefoxOS?

Thanks.


回答1:


I recommend you using asyncStorage over localStorage, is an asynchronous version of localStorage, with the same api and the benefits of IndexedDB.

You can see the code and learn how to use it reading the comments of the file:

https://github.com/mozilla-b2g/gaia/blob/master/shared/js/async_storage.js




回答2:


The best IndexDB doc I can found is Using IndexDB in MDN.

And there are plenty of default Firefox OS apps (gaia) such as gallery, browser using IndexDB. You can see how it works in real life.

Or you can use the more lightweight window.localStorage API, which works like a dictionary.

localStorage.setItem(key, value); 
localStorage.getItem(key);

EDIT: Note that localStorage is not recommend because its block the main thread. You should use gaia/shared/asyncStorage instead.

For XHR you can check Firefox-OS-Boilerplate-App for a working XHR demo




回答3:


The podcasts reference app talks about both IndexedDB and SystemXHR, which is the privileged API for doing cross-domain requests: https://marketplace.firefox.com/developers/docs/apps/podcasts




回答4:


You can use DataStore in firefox Os by using data store you can also share that data with other apps and you can also give permission to other apps to write in data store or not.

you can follow this link.

https://developer.mozilla.org/en-US/docs/Archive/Firefox_OS/API/Data_Store_API/Using_the_Data_Store_API

Just for using data store your app need to certified.

navigator.getDataStores('mystore').then((store)=>{
    store[0].getLength().then((ln)=> console.log(ln))
})


来源:https://stackoverflow.com/questions/16173004/store-data-in-firefoxos

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!