Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Trusted Contributor
sabanim
Posts: 103
Registered: ‎03-31-2011
My Device: Curve 9330
Accepted Solution

Asking only once and storing information.

Hi

I would like on startup for the FIRST time only to have my app ask for a phone number then store that number so that when prompted the end user can choose to recieve a text from my website with out having to put in the number evertime.

 

From what I read on here you cannot just get the info with out the user's information.

I can do the ajax and the popup box.  But the storing and the first time only part I'm a little to "green" on.

 

Thanks

Developer
colforbin13
Posts: 28
Registered: ‎03-21-2011
My Device: Torch 9800

Re: Asking only once and storing information.

Probably the simplest way i can think of doing this is through cookies.  You can set one cookie that stores the phone number, and another that tells you if you've asked for the number before.  Then every time you launch the app, you check the second cookie, if it's not set you prompt for the phone number, otherwise don't prompt for it.

 

An intro to using cookies with JS can be found here - http://www.w3schools.com/JS/js_cookies.asp

------------------------------------
Twitter: @ChiSoxRunner
Script. Bake. Run.
Trusted Contributor
sabanim
Posts: 103
Registered: ‎03-31-2011
My Device: Curve 9330

Re: Asking only once and storing information.

awesome thanks
Developer
agungeddy
Posts: 164
Registered: ‎08-26-2010
My Device: Not Specified

Re: Asking only once and storing information.

One important thing you should now,
that cookies will be removed by system,
everytime the device restart.
Developer
TheMarco
Posts: 669
Registered: ‎02-19-2011
My Device: BlackBerry PlayBook 32GB

Re: Asking only once and storing information.

Use HTML5 local storage. It's dead easy!

 

Here's a quick example:

 

	if(!localStorage.getItem('phonenumber')) {

                // code to ask for a phone number,
                // store in a variable named 'phonenumber'

		localStorage.setItem('phonenumber', phonenumber);	
	}
        else {

                // we already have it. No need to ask again,
                // just fetch it

                phonenumber = localStorage.getItem('phonenumber');
        }

 

The cool thing is this is completely persistent. It stays stored between sessions, device resets and even upgraded versions of your app.

Staff UI Prototyper (read: full-time hacker)


My BB10 apps: Screamager | Scientific RPN Calculator | The Last Weather App

Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C

Re: Asking only once and storing information.

Adding my weight to Marco's

 

He's correct

 

That way you are totally secure

 

Local Storage is perfectly safe and (at the moment) unbreakable

 

------------------

 

 

See that Kudos thing over there - > Marco deserves this one for being so right




Click the like button if you find my posts useful!
Developer
agungeddy
Posts: 164
Registered: ‎08-26-2010
My Device: Not Specified

Re: Asking only once and storing information.


peardox wrote:

Adding my weight to Marco's

 

He's correct

 

That way you are totally secure

 

Local Storage is perfectly safe and (at the moment) unbreakable

 

------------------

 

 

See that Kudos thing over there - > Marco deserves this one for being so right


Unfortunately, html5 LocalStorage API doesn't support in OS 5 and pervious OS devices.

It olny works in OS 6 above.

unfortunately. 
Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C

Re: Asking only once and storing information.

I have to cater for this next week - the code I inherited to work on is local storage based but I want the app to work on 5 as well (plus crappy nokias, iThingies and droids) so I'm going to write an abstraction layer to use whatever is suitable to the device

 

In the case of OS5 this can just be a DB

 

BB have written a JS wrapper for a lot of the Gears stuff so that you can tranparently use native BB APIs

 

Sadly, they ain't handled local storage (yet?)




Click the like button if you find my posts useful!
Developer
TheMarco
Posts: 669
Registered: ‎02-19-2011
My Device: BlackBerry PlayBook 32GB

Re: Asking only once and storing information.

Since RIM insists on keeping all WebWorks related posts in one forum whether they're PlayBook or smartphone apps maybe we should label our posts as such or something.

 

I blindly assumed it was PlayBook related.

Staff UI Prototyper (read: full-time hacker)


My BB10 apps: Screamager | Scientific RPN Calculator | The Last Weather App

Trusted Contributor
sabanim
Posts: 103
Registered: ‎03-31-2011
My Device: Curve 9330

Re: Asking only once and storing information.

ah My understanding is that webworks will work on both playbook and smartphone 5 and future events. Am I correct in assuming that  all smartphones apple droid bb and eventually windows will all go html5.  Just think a universal mobile language John Lenon would be so proud!