Discussion Forums  >  Uncategorized

Replies: 24    Views: 3313

mikoz
I hate code!
Profile
Posts: 51
Reg: Nov 14, 2010
Australia
3,610
05/17/11 05:41 PM (14 years ago)

pic2shop barcode scanner via custom html page

Gday, I came across this method that sort of works of starting a barcode scanner from within a buzztouch v1.5 app, but am having a little difficulty getting it to launch correctly on the first try. http://www.pic2shop.com/demo/scan_source.html This code enables you to push a button to launch the pic2shop barcode scanner if it is installed on your iphone, and if it is not installed takes you to the itunes page to get it. The problem that is happening is that when you push the scan button error 110 comes up (the url can't be shown) and it immediately takes you to the itunes install page regardless of whether it is installed already or not? But if you just reopen your app again without refreshing a second push on the scan button opens the scanner successfully and it works great. I am not any good with code but I'm pretty sure it could be something pretty useful for a number of people if this little kink in the code were straightened out. Another method I have been toying with is with the zxing project Barcodes Scanner. But it currently only has support for QRCode on the iphone and the scan button doesnt launch the app at all. http://chris.m0nk3y.net/blog/post/scanning-barcodes-from-your-mobile-web-apps http://chris.m0nk3y.net/blog/examples/barcode/index.cfm Any help on this issue would be great. Cheers Mick
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
05/17/11 11:13 PM (14 years ago)
Hi in Australia: Did you see this? http://www.pic2shop.com/developers.html It looks like the implementation you posted is for use in a web-page, it makes sense that you would use the Custom HTML screen to copy-n-paste the data. I did the same thing here to see what would happen. As expected, I get the same error you get. It looks like there are a few steps necessary to get this to work natively in an iOS app. They don't look difficult (the URL I posted) but are a bit nerdy if you're not tech-interested. The file/s you'll want to implement these steps depend on what buzztouch version you're running. v1.4 or v1.5. I'm happy to offer some guidance....post what version you're running and we'll go from there.
 
mikoz
I hate code!
Profile
Posts: 51
Reg: Nov 14, 2010
Australia
3,610
like
05/17/11 11:44 PM (14 years ago)
Gday David, Thank you kindly for looking into this for me. Im running v1.5 in my BT app. I did have a little look into the link you posted but am a little bamboozled by the code structure and when I copy/pasted those code snippets into my html page I only got a white screen result. I look forward to your help... Cheers Mick
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
05/18/11 12:08 AM (14 years ago)
Bamboozled - havn't heard that in years! So... the code snippets at that URL are not meant for the HTML itself, they get added to your Objective C project. Like I said, nerdy stuff. I've not worked with this add-on but undrestand exactly what they are doing - makes perfect sense. The idea is this: When the HTML loads (the HTML you posted) it looks find. But, when the button is clicked, the built-in browser (the one in your application) has zero understanding of the web-address associated with the button click. This is because it's not a web-address, it's an address or 'pointer' to the scanner app. In iOS this is called a Shared Application URL. So.. the web-browser doesn't understand what to do. The goal will be to intercept this click (by inspecting the URL that the browser is trying to load) and doing something different if it contains the scanner address (the address to the app). The adjustment I'll create, then share with you will be: a) Intercept this button click b) See if the users device has the scanner app installed c) If it does, launch it (pushing your app to the background) d) If it does not, take user to iTunes to get it. Some source-code will need to be adjusted to pull this off. I'll tinker with it, then create a document outlining the needed changes. It will take me a day or two to get this worked out. If you don't hear anything on this thread by say Thursday or so give the post a nudge ;-)
 
mikoz
I hate code!
Profile
Posts: 51
Reg: Nov 14, 2010
Australia
3,610
like
05/18/11 01:10 AM (14 years ago)
Thank you so much for that. I would have lost on this for ages. Look forward to hearing from you. Cheers Mick
 
mikoz
I hate code!
Profile
Posts: 51
Reg: Nov 14, 2010
Australia
3,610
like
05/19/11 05:20 AM (14 years ago)
Digging around further into this today I decided to try out some of the many open-source sdk's out there, and was absolutely blown away with zbar. http://zbar.sourceforge.net/iphone/index.html The scanning ability of this app is amazing! I was impelled to run about the house scanning everything I could find like laser-tag!!! If only I had the chops to Frankenstein that sdk into my BT xcode project?
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
05/19/11 09:21 AM (14 years ago)
Another think on my list to checkout - thanks for that ;-)
 
mikoz
I hate code!
Profile
Posts: 51
Reg: Nov 14, 2010
Australia
3,610
like
05/20/11 01:47 PM (14 years ago)
G'day David, Any chance of progress on the pic2shop launch? Cheers Mick
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
05/23/11 03:39 AM (14 years ago)
Hi again. I spent some time on this over the weekend. I ended up making some adjustments to the control panel so allow for Custom URL Schemes in the Launch Native app feature. Do this: a) Redownload the source-code to your project, it's been changed. b) Add a Launch Native App item to one of your menu's c) When choosing the type of application from the drop-down list, choose Custom URL Scheme - Third Party App. d) Enter pic2shop: in the Data String Test on a device and see what happens. I didn't install the Pic2Shop app on any devices to test this. The idea is to first see if we can get your device to launch the pic2Shop app nativey. If we can, the next step will be determining what to do with the scanned data (the callback).
 
mikoz
I hate code!
Profile
Posts: 51
Reg: Nov 14, 2010
Australia
3,610
like
05/23/11 05:47 AM (14 years ago)
Oh my god, you rock! First thing in the morning I will get stuck into it and let you know how I go. Cheers Mick
 
mikoz
I hate code!
Profile
Posts: 51
Reg: Nov 14, 2010
Australia
3,610
like
05/23/11 05:17 PM (14 years ago)
Hi David, Thank you again for all that hard work you have put in, the pic2shop scanner works flawlessly with this custom URL method you have implemented. And you have opened a door to others out there to extend their apps versatility. The callback in the demo URL code is to Google product search, which has only just barely been released to Australian merchants and such there is barely any products you can scan that will give you any results here. I currently have 2 uses for the barcode scanner in my app. 1)I'd ideally like to have pic2shop search my website (www.derivan.com.au) with the scanned data and open the page relevant in safari (for general public app use). 2)In my retailer password protected menu I would like our distributors to be able to create an order-form with the scanned data and submit it to us by email? (is this even possible?) Any ideas you may have are definitely welcomed. Cheers Mick
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
05/24/11 01:04 AM (14 years ago)
I've been pondering dozens of cool things to do with bar-codes but havn't spent much time figuring it all out. I'm a database guy and tying codes to database records (products, other neat things) is super exicitng and endless really. I'm confused as to how the darn codes get created and mapped to any useful data? Learning for another time I guess. So now that the app launches the scanner...when the scanner is done... what happens? I see in their docs how to access the scanned results but I have no idea what this is. A number? A series of letters? Who decides what the value is? Funny.
 
mikoz
I hate code!
Profile
Posts: 51
Reg: Nov 14, 2010
Australia
3,610
like
05/24/11 07:11 PM (14 years ago)
Thinking about the next step, I am going to register my app with its own custom URL scheme for the callback with BT_Info.plist. But the issue then will be once the data (EAN13 or EAN8 barcode (13 or 8 digit number)) has been returned to my app, how would I tie it to an automated website search protocol to display the correct product page? Mick
 
mikoz
I hate code!
Profile
Posts: 51
Reg: Nov 14, 2010
Australia
3,610
like
05/24/11 08:22 PM (14 years ago)
So the custom URL scheme works exactly like it should to call back the app. After scanning the barcode my app home screen reappears instantly and nothing happens. pic2shop://scan?callback=derivanv15://EAN I'm guessing that the EAN tag is replaced at scan time with the barcode number that was scanned. What would be the correct way to put into this code a line to search a specific website or the app itself for the EAN collected data? What I have already tried; I setup an app search page and tried this code... pic2shop://scan?callback=derivanv15://search/EAN but it still just loaded the app home page.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
05/24/11 11:11 PM (14 years ago)
This is great news. It sounds like it's working exactly as we expect and now it's our job to do something with the returned data..We'll need to do two things: a) Implement a method that fires to 'handle' the bar code info returned from the scanner. This method is - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { NSLog(@got barcode: %@, [url host]); } I got this from: http://www.pic2shop.com/developers.html The method needs to be added to your app's delegate filie. BT_Config > [YOURAPPNAME]_appDelegate.m See if you can get that implemented. Run the app with your device connected to Xcode and look at the console, is it outputting the URL returned? If it is, we can move to the last step... b) The last step will be to open a browser with the URL. You could open the native Safari browser or you could open the built-in browser in your buzztouch app. The second approach would allow you to control the output. Either way, you'll need to figure out what data to show when the URL loads. Re-post if you get this far and I'll show you how to create a buzztouch Custom URL screen in code, dynamically then show it in your app. Oh, wait, another way to do this: You could create a Custom URL screen in your control panel, then we could open that screen using the built in 'open screen with nickname' method.
 
mikoz
I hate code!
Profile
Posts: 51
Reg: Nov 14, 2010
Australia
3,610
like
05/24/11 11:51 PM (14 years ago)
I guess step a) works though i did get some yellow triangles (control reaches end of non-void function) Here is the output from xcode: 2011-05-25 16:36:20.071 derivanv15[1780:707] BT_application: screenType is BT_screen_launchNativeApp for screen with nickname: pic2shop and itemId: 5C2A310DC27A3CDCCCC3240 2011-05-25 16:36:20.072 derivanv15[1780:707] BT_viewControllerManager: handleTapToLoadScreen 2011-05-25 16:36:20.074 derivanv15[1780:707] BT_viewControllerManager: the parent screen nickname: Derivan Home itemId: 7ADC3D88C4BE893D2AFACC6 itemType: BT_screen_menuButtons 2011-05-25 16:36:20.075 derivanv15[1780:707] BT_viewControllerManager: the menu/button tapped is itemId: 767FD81A507ABD117CA17BB 2011-05-25 16:36:20.076 derivanv15[1780:707] BT_viewControllerManager: the screen to load is nickname: pic2shop itemId: 5C2A310DC27A3CDCCCC3240 itemType: BT_screen_launchNativeApp 2011-05-25 16:36:30.149 derivanv15[1780:707] got barcode: (null) 2011-05-25 16:36:30.155 derivanv15[1780:707] derivanv15_appDelegate: applicationDidBecomeActive 2011-05-25 16:36:30.158 derivanv15[1780:707] derivanv15_appDelegate: reportToCloud 2011-05-25 16:36:30.166 derivanv15[1780:707] BT_strings: mergeBTVariablesInString (after merge): http://www.buzztouch.com/appdata/v1.5.php?command=reportToCloud&appGuid=EAB43D706AF6CB09EF0122326&apiKey=236BF2DD1BF53AE466A6482&deviceId=24be1b37e5a5d9359e93e918bbec9221effad276&deviceLatitude=-33.820946&deviceLongitude=151.090257&deviceModel=iPhone&userId= 2011-05-25 16:36:30.171 derivanv15[1780:707] derivanv15_appDelegate: reporting to cloud at : http://www.buzztouch.com/appdata/v1.5.php?command=reportToCloud&appGuid=[buzztouchAppId]&apiKey=[buzztouchAPIKey]&deviceId=[deviceId]&deviceLatitude=[deviceLatitude]&deviceLongitude=[deviceLongitude]&deviceModel=[deviceModel]&userId=[userId] 2011-05-25 16:36:30.364 derivanv15[1780:707] BT_locationManager: didUpdateToLocation 2011-05-25 16:36:30.796 derivanv15[1780:707] derivanv15_appDelegate: lastModified (value on server): Wed, 25 May 2011 05:08:29 -0700 2011-05-25 16:36:30.800 derivanv15[1780:707] BT_fileManager: File does exist in cached directory: appModified.txt 2011-05-25 16:36:30.802 derivanv15[1780:707] BT_fileManager: readTextFileFromCacheWithEncoding: appModified.txt encoding: -1 2011-05-25 16:36:30.822 derivanv15[1780:707] derivanv15_appDelegate: previousModified (value on device): Wed, 25 May 2011 05:08:29 -0700 2011-05-25 16:36:30.823 derivanv15[1780:707] BT_fileManager: saveTextFileToCacheWithEncoding: appModified.txt encodingFlag: -1 Mick
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
05/25/11 12:00 AM (14 years ago)
OK...cool. Non-void is because our method expects a return value of TRUE or FALSE and we are retunring nothing. Add return TRUE after the NSLog statement like this: - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { NSLog(@got barcode: %@, [url host]); return TRUE; } (as usual, the double quotes are removed by the forum). So..this will get rid of the yellow warnings. But, I don't think it will change the fact that the scanner is returning NULL for the value. Look at the console, you can see where our new method is being called just before the applicationDidBecomeActive line. The value of the URL is null. We need to get this to print the data returned by the scanner. Could it be that the URL Scheme we entered in the control panel launches the app but doesn't have enough info to return any values? I'm asking because the reference on their site says it should look like like this were EAN is replaced with the value of the scanner. They show: pic2shop://scan?callback=p2sclient%3A//EAN Try using this in your control panel: pic2shop://scanvalue=//EAN Be sure to refresh the app then look at the console again after scanning something...anything change?
 
mikoz
I hate code!
Profile
Posts: 51
Reg: Nov 14, 2010
Australia
3,610
like
05/25/11 12:17 AM (14 years ago)
Coool yellow triangles are history! I tried a few variations of that line you printed watching the output and the one that worked is... pic2shop://scan?callback=derivanv15://EAN 240 itemType: BT_screen_launchNativeApp 2011-05-25 17:08:08.930 derivanv15[1780:707] got barcode: 9310097548301 2011-05-25 17:08:08.955 derivanv15[1780:707] derivanv15_appDelegate: applicationDidBecomeActive 2011-05-25 17:08:08.959 derivanv15[1780:707] derivanv15_appDelegate: reportToCloud
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
05/25/11 12:34 AM (14 years ago)
AWESOME!!! So...the long number is related to the bar-code you just read. Now sure how, but it is. What the heck did you scan anyway? The next step will be to launch the browser. Lets start by firing up the native Safari Browser to make sure loads the page we want. Just below the NSLog line, and just above the return TRUE line...This is not an ideal solution but should work for testing. I say this because we are asking the phone to launch of series of apps. First your app, then the scanner, then your app again, then Safari - seems jenky. We'll want to open the URL in your app but only after making sure this works. //just above the return TRUE line in our new method: NSURL *urlToOpen = [NSURL URLWithString:[NSString stringWithFormat:@'http://www.google.com/?code=%@', [url host]]]; [[UIApplication sharedApplication] openURL:urlToOpen]; (change single quotes to double quotes)
 
mikoz
I hate code!
Profile
Posts: 51
Reg: Nov 14, 2010
Australia
3,610
like
05/25/11 02:22 AM (14 years ago)
Thanks David, I will get stuck into it again in the morning, im so excited that it's only a bee's dick from working. But I've finished work for the day and have high-tailed it to the pub ; ) Thanks again for the fantastic support you have afforded me on this little endeavor of mine. Mick
 
mikoz
I hate code!
Profile
Posts: 51
Reg: Nov 14, 2010
Australia
3,610
like
05/25/11 04:13 PM (14 years ago)
I copied the line in you suggested, I now get a safari screen to auto open displaying google but the barcode number has not been input into the search field? Is this the result I am expecting? Mick
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
05/25/11 11:12 PM (14 years ago)
Yes, this is fine. We didn't expect anything to be in the Google Box. If you want to use Google, and pre-load the search box, you would do: NSURL *urlToOpen = [NSURL URLWithString:[NSString stringWithFormat:@'http://www.google.com/search?q=%@', [url host]]]; [[UIApplication sharedApplication] openURL:urlToOpen]; I'm not sure what page / screen you want to open?
 
mikoz
I hate code!
Profile
Posts: 51
Reg: Nov 14, 2010
Australia
3,610
like
05/25/11 11:27 PM (14 years ago)
Hi David, I want it to search our own site at first (www.derivan.com.au), as I am in the process of creating pages for individual colours per range of products. We have several different ranges of artist acrylic paints that we manufacture and I was hoping to extend the information on the labels just by scanning the products barcode with our app to display the individual page for that range/colour (approximately 3000 pages). As you can imagine this is a lot of work but the pages are already being created for another purpose also. I was hoping to add meta tags with the barcode number for the search to pick it up? Do you think that is a feasible way to accomplish this objective? Mick
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
05/26/11 12:27 AM (14 years ago)
Without know anything more than you wrote... I would do this: a) Create a database table with products (if you don't already have one) b) Add a column for barcode to hold the value that the scanner returns c) Create ONE .php page that fetches the data from the database for the product with barcode xxxxx d) Output the data the 'same' for each product. Title, price, description, image, etc. would all come from the database. The .php page is fetches this data and plugs it into the HTML template. Your scanner URL may look something like this: http://www.mysite.com/product.php?barcode=%@ After adding the code, the actual URL would look like: http://www.mysite.com/product.php?barcode=xxxxxxx Then on product.php SELECT title, price, description, whatever, whatever FROM PRODUCTS WHERE barcode = $_GET['barcode']; This is a very elementary example but I think you get the idea. 3000 seperate web-pages makes zero sense to me.
 
mikoz
I hate code!
Profile
Posts: 51
Reg: Nov 14, 2010
Australia
3,610
like
05/26/11 06:50 PM (14 years ago)
I dont have much idea about databases and php but I am going to see what I can do with filemaker pro first to create a database.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.