...you have at least three possibilities:
Below, we describe how to implement the third option on iOS. Web developers, you can use the same method to barcode enable your site, so read on!
This method requires that your users install pic2shop. However, pic2shop is, and will remain, free, so it does not cost you or your users anything. Moreover, pic2shop is lightweight (10MB), and loads very fast.
The complete Xcode and Android projects are available for download here. Feel free to reuse the sample code in your own application.
To start, the client app (your app) needs to check whether pic2shop is already installed:
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"pic2shop:"]]) {
We use the result to show or hide the buttons that offer to install pic2shop or to scan a barcode.
To take the user to the pic2shop install page do:
NSURL *urlapp = [NSURL URLWithString:
@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=308740640&mt=8"];
[[UIApplication sharedApplication] openURL:urlapp];
To start pic2shop, and tell it to call back the client app with the barcode (your app will exit or be suspended at this point !):
NSURL *urlp2s = [NSURL URLWithString:@"pic2shop://scan?callback=p2sclient%3A//EAN"];
[[UIApplication sharedApplication] openURL:urlp2s];
The part after "callback=" is the (escaped) URL that pic2shop will use to call back your app. You can change it, but you need to keep the "EAN" string somewhere, because pic2shop will replace it with the barcode digits.
Web developers, the above link is all you have to do to integrate barcode scanning in your site. In your case, the callback will be a regular URL pointing to your web app.
For the callback to work, your app needs to have registered its own URL scheme with the iPhone OS. For that, it needs to add an entry in its own Info.plist (we use the p2sclient: scheme in this example):
And finally, when it is restarted, your app needs to detect that it has been called back, and extract the barcode information from the callback URL. That is done by defining the handleOpenURL() method of the App Delegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
NSLog(@"got barcode: %@", [url host]);
}
In this simple example, the barcode is the "host" part of the URL, right after the double slash.
That's it! Have a lot of fun with barcodes! We would love to hear about the apps that you build using this system.
pic2shop is developed by Vision Smarts
For more information, visit our website at www.visionsmarts.com.
Fast. Easy. Independent. Private.
Give it a try now!