sølve tornøe
Posts: 0
Joined: Tue Jan 28, 2014 10:38 am

Barcode scanner: authenticate local storage value.

Hi! i have a barcode scanner on my app.. and i have a code to authenticate whats in a label. Its working like this: scanning a code - the info from the scan result goes in the local storage "_qr" - redirects to the result page - on load the result page displays the local storage in a label - on load 2, the javascript authenticate is running to check if "buss" is in the label. If not it displays an alert-box and redirects to home.

The problem here is that i want the authenticate code to run right after the barcode is scanned. "barcode scan complete" - then it redirects if it is right and displays an alert if wrong.

The thing is that as from where i'm standing, i cant read local storage without outputting the storage as label.
So, how can i check if the local storage contains a unique text?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Barcode scanner: authenticate local storage value.

Hello! Sorry for delay, we're working on it. I'll update.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Barcode scanner: authenticate local storage value.

"The problem here is that i want the authenticate code to run right after the barcode is scanned" - invoke service on scanner service success event
"i cant read local storage without outputting the storage as label" - you can. Check in JS code prelocalStorage.getItem("varName")/prewhere varName - localStorage variable name

sølve tornøe
Posts: 0
Joined: Tue Jan 28, 2014 10:38 am

Barcode scanner: authenticate local storage value.

Yes, but if i do "localStorage.getItem("varName")" then the "varName" is the name of the selected local storage right? example:
Scanning qr code - the output of the qr code is "fish" - fish goes in to the local storage var "_qr". so then local storage should be "fish"...

But if i want to check if the local storage = fish then how can i do that?
as i understand i cant use localStorage.getItem("_qr") ?

code as it is now:
function auth() {
if ($('#Hjem_mobilelabel_60:contains("fish")').length 0) {
document.getElementById('Resultat_mobilelabel_sted').innerHTML = 'Fish is good!';
} else {
alert("Feil qr kode!\nKoden er ikke i vårt register.");
Appery.navigateTo('Hjem', {
reverse: false
});
}
}

So as you can see.. i'm checking the local storage in an hard and bad way.
How can i improve that?

Sorry for my bad English and bad explanation skills :/ :P

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Barcode scanner: authenticate local storage value.

Hello,

[quote:]
But if i want to check if the local storage = fish then how can i do that?
as i understand i cant use localStorage.getItem("_qr") ?
[/quote]

Something like this:
pre
code
var val = localStorage.getItem("_qr");
if (val == "fish") {
alert("It's a fish");
} else {
//...
}
/code
/pre

This doc should be helpful : http://docs.appery.io/tutorials/build...

sølve tornøe
Posts: 0
Joined: Tue Jan 28, 2014 10:38 am

Barcode scanner: authenticate local storage value.

Thank you Igor Moroz!! I personally love you now! :)
Really, Thanks!

Return to “Issues”