Topic
  • 3 replies
  • Latest Post - ‏2012-12-13T22:01:32Z by SystemAdmin
B31N_Anton_Ivanopoulos
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(){
window.plugins.barcodeScanner.scan(
function(result) {
if (result.cancelled)
alert("the user cancelled the scan")
else
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 http://192.168.1.5:8080/apps/services/api/SubAccountingJQM/iphone/init
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 http://192.168.1.5:8080/apps/services/api/SubAccountingJQM/iphone/init
2012-09-26 13:31:22.648 SubAccounting4640:17903 INFO response http://192.168.1.5:8080/apps/services/api/SubAccountingJQM/iphone/init success: /*-secure-
{"userPrefs":{},"WL-Authentication-Success":{"wl_antiXSRFRealm":{"userId":"antiXSRF","attributes":{"savedInstanceId":"8q6r9kgms0itrdklug701jsf2q"},"isUserAuthenticated":1,"displayName":"antiXSRF"},"wl_deviceNoProvisioningRealm":{"userId":"device","attributes":{"mobileClientData":"com.worklight.core.auth.impl.MobileClientData@14e4cca"},"isUserAuthenticated":1,"displayName":"device"}},"gadgetProps":{"directUpdate":{"availableSkins":,"checksum":2350387247,"updateSize":387168},"ENVIRONMENT":"iphone"},"userInfo":{"wl_authenticityRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"SampleAppRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_remoteDisableRealm":{"userId":"NullLoginModule","attributes":{},"isUserAuthenticated":1,"displayName":"NullLoginModule"},"wl_antiXSRFRealm":{"userId":"antiXSRF","attributes":{"savedInstanceId":"8q6r9kgms0itrdklug701jsf2q"},"isUserAuthenticated":1,"displayName":"antiXSRF"},"WorklightConsole":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_deviceAutoProvisioningRealm":{"userId":null,"attributes":{},"isUserAuthenticated":0,"displayName":null},"wl_deviceNoProvisioningRealm":{"userId":"device","attributes":{"mobileClientData":"com.worklight.core.auth.impl.MobileClientData@14e4cca"},"isUserAuthenticated":1,"displayName":"device"},"myserver":{"userId":"11054b64-36f6-49c1-83a8-9df247624b11","attributes":{},"isUserAuthenticated":1,"displayName":"11054b64-36f6-49c1-83a8-9df247624b11"},"wl_anonymousUserRealm":{"userId":"11054b64-36f6-49c1-83a8-9df247624b11","attributes":{},"isUserAuthenticated":1,"displayName":"11054b64-36f6-49c1-83a8-9df247624b11"}}}*/
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 http://192.168.1.5:8080/apps/services/api/SubAccountingJQM/iphone/init 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
    christianIBM
    78 Posts

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

    ‏2012-09-26T15:16:40Z  
    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  
    Have you tried this on an actual device and gotten the same error?

    -Worklight Development Team, iOS-Christian Linares
    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
    SystemAdmin
    2327 Posts

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

    ‏2012-12-13T22:01:32Z  
    Maybe this can be useful

    Please download the plugin from:
    https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeScanner 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=
    "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>
    


    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, CDVBarcodeScanner.mm, 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:
    <worklightServerRootURL>http://${local.IPAddress}:*8086*</worklightServerRootURL>

    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 
    'Done' 
    // 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
    Link: https://developer.apple.com/ios/my/overview/index.action
    The app must work.

    regards,

    Jaime Alvarez
    jaimealvarezv@gmail.com