Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
586 views
in Technique[技术] by (71.8m points)

cordova - Using Local storage in phone gap

I wanted to create an mobile app for my web project. I found phonegap. It says Easily create apps using HTML, CSS, and JavaScript. I have not created a mobile app using phone gap before. There are three storage options memory-store.js (MemoryStore), ls-store.js (LocalStorageStore) and websql-store.js (WebSqlStore). I just want to save a token to recognise the user. Which storage is best suited. Is there a better way to build an mobile app.

I appreciate any help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Using Local Storage will probably be easiest for your needs.

Fundamentally speaking PhoneGap apps are native apps (so they can be distributed through app stores) that simply run a web page or pages. The PhoneGap API then provides JavaScript hooks into the device functions like camera etc. Theres more to it but for now thats the background.

So since the app is essentially a web page (HTML5, CSS, JS) you can make use of LocalStorage (part of HTML5).

Example local storage usage:

Setting values:

localStorage.myname = "Greg";

Getting values:

localStorage.myname; // returns "Greg"

More information here for local storage: http://diveintohtml5.info/storage.html

For Windows Phone 7 : http://docs.phonegap.com/en/3.4.0/cordova_storage_storage.md.html#Storage

The syntax is as below

localStorage.setItem("name", "Alen");

localStorage.getItem("name"); //will return Alen

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...