Web App with Bar Codes

I posted the beginning of this in the XOJO Pro forum and what I found a solution looks promising but I need to improve my fundamental knowledge of using HandleSpecialURL in XOJO.

The Barcode iOS app I found has a built in Web browser two configurable URL’s that work like this:

  1. First Is the optional “launch” URL that will take you to a page of your choice when the iOS app opens. It could serve as a login or other admin page.
  2. The second is a “scan” URL. Touch the camera icon on the tool bar of the app and after a successful scan the built in Web browser goes to this URL with the bar code value and symbology added as parameters in the URL.

Both of these configurable URL’s can contain pretty much any “constant” data you want.

All of this is pretty good EXCEPT the built in Web browser of course leaves the first page and you loose your session. I have been able to process the parameters in the URL to get the barcode but I can’t quite figure out what I need to do next in XOJO.

SO … Do I simply need to write my complete application to respond to these two URL’s in the HandleSpecialURL event? If so how do I handle multiple connections since my understanding is HandleSpecialURL does not have sessions?

Thanks.

Cookies are your friend.

If you’re using the first URL to authenticate your user by asking them to log into your web app, you can then save a “token string” (like a hash string or something that can’t be guessed) for that user to a tokens/sessions table, and then save their username and that token string to a cookie.

When the second URL hits HandleSpecialURL with the barcode data in the params, you can then read the cookie via the WebRequest object that you get. Check that the username/token string combination from the cookie is valid by looking it up in your database, if good then save the data etc.

Create your own sessions and put them in a cookie. Then check for the presence of the cookie each time HandleSpecialURL is accessed.

edit: Ian’s answer is best.

Thanks Ian (and Bob).

OK … that makes sense.

So, will I need to “roll my own HTML” to build a page in the HandleSpecialURL that looks nice? I suppose I can use an HTML editor to build something then paste the code into XOJO and “tweak” it.

Nope, depending on success or failure, redirect to the very same web app but with params you can use to display the right page when the Session opens. You’ll still have access to the cookie too, so could write to that if you like.

You could actually skip HandleSpecialURL totally, and just pass the barcode data as a param to a normal web app session and use it from there, updating the page that you open with success or failure messages, or a log of codes scanned etc. It would look like you’re just updating the same page, but in actuality you’re opening a new session and retrieving log history each time etc.

I was just about to ask if this was going to create a new session with each re-direct and apparently it will. Is that a “bad thing”?

Every barcode scan will create a new session.

Not really a bad thing, the sessions die off eventually and free up memory. Depends on how many users and how quickly they are scanning I guess.

A better option would be that once on the page where the bar codes are being entered, that you get to scan to an input field, at least then you could update without a brand new session for each bar code.

New Information.

I hope this is not too convoluted to understand. ;-))

When the scanner program launches it executes the “startup” URL and takes me to the XOJO login page in the built in browser. I login and it takes me to the “scan” page per the XOJO .show to load that page.

The scanner program (p2spro) on iOS implements a custom URL like below. I have this in a link in the XOJO program on the “scan” page.

p2spro://scan?formats=CODE39,EAN8&callback=javascript:insertCodeFormat('CODE','FORMAT')

When I touch the link iOS asks permission to run the p2spro scanner program and it launches.

The scanner program has a configurable URL of what to do after the scan is complete. It can contain any URL and substitutes the barcode value for a token in the URL. When the scan completes it runs the post scan URL in the built in Web browser and returns to the XOJO page that I just left when I touched the “scan” link and back to the original session.

They also supply a PHP demo program that has this JavaScript (below) to handle returning the scanned barcode into the text field in the demo PHP program:

<script type="text/javascript">
function insertCodeFormat(code,format) {
  $("textarea#scanresult").text(decodeURIComponent(code));}
</script>

The “textarea#scanresult” will need to change to reflect the identifiers in my XOJO program.

So … is there a way to embed this JavaScript function in the XOJO page and have it fire when I return from the scan and “stuff” the barcode value back into a WebTextField?

I was successful in making this code work on return to the XOJO program in the built in browser to display an alert box. The word CODE is replaced with the actual barcode value scanned. Apparently the callback in the URL does work.

p2spro://scan?formats=CODE39,EAN8&callback=javascript:alert('Hello CODE');

Thanks … again