3 replies Latest Post - ‏2012-12-13T22:01:32Z by SystemAdmin
2 Posts

Pinned topic How to add / use the Cordova Barcode Scanner plugin with Worklight (iOS)?

‏2012-09-26T03:35:35Z |
Hi all,

Struggling trying to achieve what's mentioned in the thread title. Wondering if anyone had any tips on how to get this working?

As apart of the setup, I have:
- Placed the .h, .mm, .cpp files in the Classes folder.
- Placed the barcodeScanner.js file under the www/js folder.
- Put in the 'org.apache.cordova.barcodeScanner' entry in the Cordova.plist file.
- Added the necessary libraries as according to the setup documentation:
- AVFoundation.framework
- AssetsLibrary.framework
- CoreVideo.framework
- libiconv.dylib

- And as a test of the plugin, I'm just using the basic example from the documentation:
function wlCommonInit(){
document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady(){
function(result) {
if (result.cancelled)
alert("the user cancelled the scan")
alert("we got a barcode: " + result.text)
function(error) {
alert("scanning failed: " + error)

However, when I run the application in the iOS simulator, I get the following output:

2012-09-26 13:31:19.460 SubAccounting4640:17903 Web resources integrity test is disabled.
2012-09-26 13:31:19.585 SubAccounting4640:17903 Multi-tasking -> Device: YES, App: YES
2012-09-26 13:31:21.890 SubAccounting4640:17903 INFO ondeviceready event dispatched
2012-09-26 13:31:21.891 SubAccounting4640:17903 {
appVersionPref = "1.0";
freeSpace = 112269139968;
wlSkinLoaderChecksum = "(null)";
wlSkinName = default;
2012-09-26 13:31:21.895 SubAccounting4640:17903 INFO wlclient init started
2012-09-26 13:31:21.896 SubAccounting4640:17903 INFO Read cookies: null
2012-09-26 13:31:21.897 SubAccounting4640:17903 INFO CookieMgr read cookies: {}
2012-09-26 13:31:22.162 SubAccounting4640:17903 INFO Request
2012-09-26 13:31:22.632 SubAccounting4640:17903 DeviceAuthManager:getWorklightUniqueDeviceId --> returning UUID from the keychain
2012-09-26 13:31:22.636 SubAccounting4640:17903 INFO Request
2012-09-26 13:31:22.648 SubAccounting4640:17903 INFO response success: /*-secure-
2012-09-26 13:31:22.648 SubAccounting4640:17903 INFO wlclient connect success
2012-09-26 13:31:22.649 SubAccounting4640:17903 INFO before: app init onSuccess
2012-09-26 13:31:22.650 SubAccounting4640:17903 ERROR exception.

I'm not totally sure what is causing this, I've used the plugin previously with Phonegap / Cordova on its own, but never with Worklight. Does anyone have any ideas?

Thanks in advance!
  • christianIBM
    78 Posts

    Re: How to add / use the Cordova Barcode Scanner plugin with Worklight (iOS)?

    ‏2012-09-26T15:16:40Z  in response to B31N_Anton_Ivanopoulos
    Have you tried this on an actual device and gotten the same error?

    -Worklight Development Team, iOS-Christian Linares
    • B31N_Anton_Ivanopoulos
      2 Posts

      Re: How to add / use the Cordova Barcode Scanner plugin with Worklight (iOS)?

      ‏2012-10-06T05:01:29Z  in response to christianIBM
      Hi Christian,

      Yes, I've also tested it on an actual device but I get the same error as what appears in the simulator.

      Also, I am testing my application in iOS6.
  • SystemAdmin
    2327 Posts

    Re: How to add / use the Cordova Barcode Scanner plugin with Worklight (iOS)?

    ‏2012-12-13T22:01:32Z  in response to B31N_Anton_Ivanopoulos
    Maybe this can be useful

    Please download the plugin from: and uncompress it.

    Follow the steps:

    1. Create a new worklight project with a Hibrid App, then add a new iphone environment.
    2. Open the file plugin.xml into the uncompresed folder, you should see something like:
    <!-- ios --> <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=
    "" /> <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>

    3. Inside the folder .../iphone/native/classes copy the following files (the same files showed in the file plugin.xml)

    scannerOverlay.xib, zxing-all-in-one.h,, zxing-all-in-one.cpp

    4. Use xcode to open the xcode project from .../iphone/native/ folder and ...
    a) Change the opction "deployment target" to ver 6 in the Summary tab
    b) Change the parameter "build active Architecture Only" to "YES" in the "Build settings" tab
    c) In te "Build Phases" tab expand the row "Bind Binary With Libraries" and add the following frameworks (see the plugin.xml file)
    <framework src=
    "libiconv.dylib" /> <framework src=
    "AVFoundation.framework" /> <framework src=
    "AssetsLibrary.framework" /> <framework src=
    "CoreVideo.framework" />

    Dont forget use the "+" button in the middle of the window, you can find them using the filter.

    d) In the xcode project find the Cordova.plist file and add the plugin (key=BarCodeScanner, Value=CDVBarcodeScanner)
    5. copy the barcodescanner.js file to .../apps/App-name/common/js

    6. Add the barcodescanner.js entry to any html that uses the plugin.
    Use: <script type="text/JavaScript" src="js/barcodescanner.js"></script>

    7. Config into application-descriptor.xml the URL of the server, sometink like:

    8. Add the following code into the main html:
    <button onclick=
    "captureBarCode();">Capture Bar Code</button>

    and the javascript:
    <script type=
    "text/javascript"> function captureBarCode() 
    { window.plugins.barcodeScanner.scan(function(result) 
    { showAlert(
    "We got a barcode\n" + 
    "Result: " + result.text + 
    "\n" + 
    "Format: " + result.format + 
    "\n" + 
    "Cancelled: " + result.cancelled); 
    }, function(error) 
    { showAlert(
    "Scanning failed: " + error); 
    }   function alertDismissed() 
    // do something 
    }   function showAlert(msg) 
    { navigator.notification.alert(msg, 
    // message alertDismissed, 
    // callback 
    'Window title', 
    // title 
    // buttonName ); 
    } </script>

    9. Right click in App-name -> run as -> Build All and Deploy

    10. Run the app using xcode into the iphone/ipod, see
    The app must work.


    Jaime Alvarez