In this article we will learn how to integrate IBM Worklight 5.0.6 + PhoneGap BarcodeScanner functionality,Following steps are given.
Make sure downloading iOS/ChildBrowser
download the ChildBrowser Plugins from https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeScanner
or
download folder phonegap-plugins-master and locate
phonegap-plugins-master\phonegap-plugins-master\iOS\BarcodeScanner(recommended).
1)Create Worklight Project + app like
2) In common/WLBarcodeApp.html add code
<button onclick="barcodeScan();">Barcode Scan</button>
<div id="mydiv">
</div>
$('#mydiv').html('');
window.plugins.barcodeScanner.scan(
function(result) {
$('#mydiv').html('Barcode: '+result.text);
});
}
4)After creation of Worklight Project and application locate Project/apps/common and right click New Worklight Environment checked iPhone and finish.
From the downloaded files
a)Copy barcodescanner.js into common/js/
b)Copy 1)CDVBarcodeScanner.mm 2)scannerOverlay.xib 3)zxing-all-in-one.cpp 4)zxing-all-in-one.h into iPhone/native/Classes/ it will looks like
<plugin name="org.apache.cordova.barcodeScanner" value="CDVBarcodeScanner" />
</plugin>
<header-file src="zxing-all-in-one.h" />
<source-file src="CDVBarcodeScanner.mm" />
<source-file src="zxing-all-in-one.cpp" />
<framework src="libiconv.dylib" />
<framework src="AVFoundation.framework" />
<framework src="AssetsLibrary.framework" />
<framework src="CoreVideo.framework" />
</platform>.
7)After successfully imported Worklight project in Xcode environment select the top of the project and select add to
select classes from window 1)CDVBarcodeScanner.mm 2)scannerOverlay.xib 3)zxing-all-in-one.cpp 4)zxing-all-in-one.h then press add button.
Make sure downloading iOS/ChildBrowser
download the ChildBrowser Plugins from https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeScanner
or
download folder phonegap-plugins-master and locate
phonegap-plugins-master\phonegap-plugins-master\iOS\BarcodeScanner(recommended).
1)Create Worklight Project + app like
2) In common/WLBarcodeApp.html add code
<button onclick="barcodeScan();">Barcode Scan</button>
<div id="mydiv">
</div>
3)In common/js/WLBarcodeApp.js add following function
function barcodeScan()
{$('#mydiv').html('');
window.plugins.barcodeScanner.scan(
function(result) {
$('#mydiv').html('Barcode: '+result.text);
});
}
From the downloaded files
a)Copy barcodescanner.js into common/js/
b)Copy 1)CDVBarcodeScanner.mm 2)scannerOverlay.xib 3)zxing-all-in-one.cpp 4)zxing-all-in-one.h into iPhone/native/Classes/ it will looks like
5)In IBM Worklight 5.0.6 version provide config.xml file, Located in iPhone/native/config.xml add the following entries
<plugin>
<plugin name="BarcodeScanner" value="CDVBarcodeScanner" /><plugin name="org.apache.cordova.barcodeScanner" value="CDVBarcodeScanner" />
</plugin>
After </plugin> head insert below code
<platform name="ios"> <plugins-plist key="BarcodeScanner" string="CDVBarcodeScanner" />
<resource-file src="scannerOverlay.xib" /> <header-file src="zxing-all-in-one.h" />
<source-file src="CDVBarcodeScanner.mm" />
<source-file src="zxing-all-in-one.cpp" />
<framework src="libiconv.dylib" />
<framework src="AVFoundation.framework" />
<framework src="AssetsLibrary.framework" />
<framework src="CoreVideo.framework" />
</platform>.
6) Now its time to playing in xcode environment just right click the iPhone Generated environment and select run as Xcode project
select classes from window 1)CDVBarcodeScanner.mm 2)scannerOverlay.xib 3)zxing-all-in-one.cpp 4)zxing-all-in-one.h then press add button.
8.Another most important step is to add library files into project for this Select Project Targets Build Phases Link Binary with Libraris and locate + sign and add following four libraries one by one
AssetsLibrary.framework, AVFoundation.framework, CoreVideo.framework, libiconv.dylib.
Its time to run on device here are the screens that show the running
run time screen
Final Screen
Thank You,
Best Regards,
Sajjad Hussain
Hi, your blog/tutorial here had helped me tremendously! I was creating a Worklight project with Worklight v6, and was looking for the correct way to integrate with BarcodeScanner plugin.
ReplyDeleteJust one thing that I found, at least with the version of plugin that I downloaded, I need to add "extern" prefix to the declaration line: https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git;a=blob;f=CordovaLib/Classes/CDVPlugin.h;h=33ba1c4bace189ce068987faa61877bc9a1a5dfc;hb=9facafb4
Again, thanks so much for this post!!
Hi reedglow, Thanks for your feedback. Happy to see that this article is helpful for you.
ReplyDeleteThank you so much.
Thanks a lot for this tutorial. Very helpful.
ReplyDeleteI am using xcode 5.1.1 and worklight 6,testing in the device iphone 5s.I am unable to see barcodeScan button
ReplyDeleteHi,On click of barcode scan button camara is not opening
ReplyDeleteThe barcode scanner C# code project that I have been using is CnetSDK, and it feels good. Both 1D barcode and 2D Qrcode can be read very well.
ReplyDelete