Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on scanner click function #1

Open
marcwhitbread opened this issue Aug 10, 2014 · 16 comments
Open

Error on scanner click function #1

marcwhitbread opened this issue Aug 10, 2014 · 16 comments

Comments

@marcwhitbread
Copy link

2014-08-10 12:59:37.166 Grocery[6356:60b] CDVPlugin class com.phonegap.plugins.barcodescanner.BarcodeScanner (pluginName: BarcodeScanner) does not exist.
2014-08-10 12:59:37.166 Grocery[6356:60b] ERROR: Plugin 'BarcodeScanner' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2014-08-10 12:59:37.167 Grocery[6356:60b] -[CDVCommandQueue executePending] [Line 158] FAILED pluginJSON = [
  "BarcodeScanner890466376",
  "BarcodeScanner",
  "scan",
  [

  ]
]

Config.xml has the following added:

<feature name="BarcodeScanner">
    <param name="android-package" value="com.phonegap.plugins.barcodescanner.BarcodeScanner" />
    <param name="ios-package" value="com.phonegap.plugins.barcodescanner.BarcodeScanner" />
</feature>

<!-- phonegap directives -->
<gap:plugin name="com.phonegap.plugins.barcodescanner" />

Is there a reason why your config.xml is in www in stead of in the project root?

Any ideas where I might look to confirm that com.phonegap.plugins.barcodescanner.BarcodeScanner has been installed correctly? (it's appearing in the project /plugins/ folder)

@jlinoff
Copy link
Owner

jlinoff commented Aug 11, 2014

Hi Marc,

Any ideas where I might look to confirm that
com.phonegap.plugins.barcodescanner.BarcodeScanner
has been installed correctly? (it's appearing in the project /plugins/ folder)

If it is in your project subfolder, then it should be working in phonegap. Have you tried building locally (either Android and iOS) and testing it? I typically do that using ripple or the native tools before uploading to PhoneGap.

Is there a reason why your config.xml is in www in stead of in the project root?

Thanks for pointing that out. When I first set this PhoneGap required the config.xml to be in www. They have changed that since then.

You might try copying your config.xml to the xml folder just to see whether that makes a difference. If that works, you may need to update your cordova and phonegap installations.

If you are still having trouble tomorrow, let me know and I will see if i can build a new example with updated versions of cordova, phonegap, angularjs and ionic.

@marcwhitbread
Copy link
Author

If it is in your project subfolder, then it should be working in phonegap. Have you tried building locally (either Android and iOS) and testing it? I typically do that using ripple or the native tools before uploading to PhoneGap.

It builds and runs in the ios emulator successfully if that's what you mean. The barcode scanning functionality doesn't word anywhere. I assumed this was because the camera doesn't exist in the emulator. I will look into ripple. I'm fairly new to native app development.

You might try copying your config.xml to the xml folder just to see whether that makes a difference. If that works, you may need to update your cordova and phonegap installations.

I assumed that was the issue and moved it accordingly. I'm running cordova 3.5, installed via the CLI. There weren't any instructions regarding PhoneGap. Have I missed something? I thought it was bundled with a version.

If you are still having trouble tomorrow, let me know and I will see if i can build a new example with updated versions of cordova, phonegap, angularjs and ionic.

If it's super easy for you then I would appreciate the help. I've been running into dead ends for the past few days and finally decided to reach out because your example is applicable to my project.

Let me know if you have any questions about my setup. I'm using AngularJS, Cordova CLI and Xcode to build and deploy the app on an iPhone 5 (7.1.2).

@jlinoff
Copy link
Owner

jlinoff commented Aug 11, 2014

I am happy to help. I appreciate you taking the time to try my post and report that you are having problems. I would like to get it working so that everyone can benefit. I am not sure how quickly I can turn the example but I will try to do it as soon as possible.

@jlinoff
Copy link
Owner

jlinoff commented Aug 11, 2014

How did you install the plugin into your project? Did you use this command?

$ cordova plugin add http://github.com/phonegap-build/BarcodeScanner.git

When I did that I had to remove and then re-add my platforms to get everything working:

$ ionic platform remove ios android
$ ionic platform list
Installed platforms: 
Available platforms: amazon-fireos, android, blackberry10, firefoxos, ios
$ ionic platform add ios android
$ ionic platform list
Installed platforms: android 3.5.0, ios 3.5.0
Available platforms: amazon-fireos, blackberry10, firefoxos
$ ionic build ios
[ output snipped ]
$ ionic build android
[ output snipped ]

I then manually checked for the plugin for both android and ios for a simple test app: test01:

$ cordova plugins
com.ionic.keyboard 1.0.2 "Keyboard"
com.phonegap.plugins.barcodescanner 1.2.0 "BarcodeScanner"
org.apache.cordova.console 0.2.10 "Console"
org.apache.cordova.device 0.2.11 "Device"

$ # for android look for the jar file
$ ls -1 ./platforms/android/ant-build/dexedLibs/com.google.zxing.client.android.captureactivity-91999b7f0fa89541fae891f1f9c399ac.jar
./platforms/android/ant-build/dexedLibs/com.google.zxing.client.android.captureactivity-91999b7f0fa89541fae891f1f9c399ac.jar

$ # for ios look for the mm file
$ ls -1 ./platforms/ios/test01/Plugins/com.phonegap.plugins.barcodescanner/CDVBarcodeScanner.mm
./platforms/ios/test01/Plugins/com.phonegap.plugins.barcodescanner/CDVBarcodeScanner.mm

Does this help at all?

@jlinoff
Copy link
Owner

jlinoff commented Aug 11, 2014

I also verified that the current PgBarcodeScanner application worked in phonegap: https://build.phonegap.com/apps/992106/share for ios, android and windows.

@marcwhitbread
Copy link
Author

I successfully completed all of your steps. All the responses in the CLI are identical. All the files are in the right place.

I'm still getting the same error when i click "Click to scan".

The only variable now must be on the deployment end. I must be doing something incorrectly...

After your build process, I test the app 1 of 2 ways which both have resulted in the same errors in the console.

  1. $ cordova emulate ios
  2. I open the .xcodeproj file (platforms/ios/PgBarcodeScanner.xcodeproj) in Xcode 5.1.1 and run (CMD+R or Product > Run in the top menu) to deploy the app to the device for testing. Once the project is loaded in Xcode, I get the following deprecation warnings:
PgBarcodeScanner Group
/Applications/MAMP/htdocs/git/grocery/platforms/ios/PgBarcodeScanner/Plugins/com.phonegap.plugins.barcodescanner/CDVBarcodeScanner.mm
/Applications/MAMP/htdocs/git/grocery/platforms/ios/PgBarcodeScanner/Plugins/com.phonegap.plugins.barcodescanner/CDVBarcodeScanner.mm:262:6: 'presentModalViewController:animated:' is deprecated: first deprecated in iOS 6.0
/Applications/MAMP/htdocs/git/grocery/platforms/ios/PgBarcodeScanner/Plugins/com.phonegap.plugins.barcodescanner/CDVBarcodeScanner.mm:271:32: 'dismissModalViewControllerAnimated:' is deprecated: first deprecated in iOS 6.0
/Applications/MAMP/htdocs/git/grocery/platforms/ios/PgBarcodeScanner/Plugins/com.phonegap.plugins.barcodescanner/CDVBarcodeScanner.mm:640:23: 'isOrientationSupported' is deprecated: first deprecated in iOS 6.0
/Applications/MAMP/htdocs/git/grocery/platforms/ios/PgBarcodeScanner/Plugins/com.phonegap.plugins.barcodescanner/CDVBarcodeScanner.mm:641:23: 'setOrientation:' is deprecated: first deprecated in iOS 6.0
/Applications/MAMP/htdocs/git/grocery/platforms/ios/PgBarcodeScanner/Plugins/com.phonegap.plugins.barcodescanner/CDVBarcodeScanner.mm:653:33: 'orientation' is deprecated: first deprecated in iOS 6.0
/Applications/MAMP/htdocs/git/grocery/platforms/ios/PgBarcodeScanner/Plugins/com.phonegap.plugins.barcodescanner/CDVBarcodeScanner.mm:850:33: 'orientation' is deprecated: first deprecated in iOS 6.0

Clicking the scan button produces the same error message in both the simulator and the real device:

2014-08-12 11:21:53.326 PgBarcodeScanner[7934:60b] CDVPlugin class com.phonegap.plugins.barcodescanner.BarcodeScanner (pluginName: BarcodeScanner) does not exist.
2014-08-12 11:21:53.328 PgBarcodeScanner[7934:60b] ERROR: Plugin 'BarcodeScanner' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2014-08-12 11:21:53.329 PgBarcodeScanner[7934:60b] -[CDVCommandQueue executePending] [Line 158] FAILED pluginJSON = [
  "BarcodeScanner1489781331",
  "BarcodeScanner",
  "scan",
  [

  ]
]

How are you confirming that the barcode scanner worked? What does your deployment to an ios device/simulator process look like?

Thanks again for all the help by the way. :)

@jlinoff
Copy link
Owner

jlinoff commented Aug 12, 2014

It sounds like you are doing everything correctly. Hmmmm.....

How are you confirming that the barcode scanner worked?

I confirmed it by downloading it to a Samsung S3 and an iPhone 4 but it should be possible to confirm it in ripple by telling ripple to use your laptop/workstation camera. Actually I just tried it in ripple and it didn't work which surprises me because I am almost sure that I originally tested it there using my laptop camera.

Let me see whether I can get it working in ripple and get back to you.

What does your deployment to an ios device/simulator process look like?

The deployment was done by phonegap so I don't really know. I just used the QR code to do the installation on my device.

Thanks again for all the help by the way. :)

Glad to help. I want to figure out how to get it working for you.

If it would help, I would be glad to send you the entire contents of the project directory.

@jlinoff
Copy link
Owner

jlinoff commented Aug 12, 2014

I am running iOS 7.1.2 on my iphone4.

When I run ripple I do not see a popup complaining about BarcodeScanner.scan. That is suspicious.

Are you building your environment using phonegap, cordova or ionic?

@marcwhitbread
Copy link
Author

Are you building your environment using phonegap, cordova or ionic?

Just to be 100% sure. By build do you mean:

$ ionic build ios

@jlinoff
Copy link
Owner

jlinoff commented Aug 12, 2014

Yup and that is what I used.

Have you tried zipping your www directory and submitting it phonegap?

@jlinoff jlinoff closed this as completed Aug 12, 2014
@jlinoff jlinoff reopened this Aug 12, 2014
@jlinoff
Copy link
Owner

jlinoff commented Aug 12, 2014

Sorry, clicked the wrong button...

@marcwhitbread
Copy link
Author

I've never done it with PhoneGap before. I'll have to look up how to do that. Any quick resources I should look at for getting it on an iPhone? Is http://build.phonegap.com the best way?

@jlinoff
Copy link
Owner

jlinoff commented Aug 12, 2014

That is interesting. I wonder if my app does not work unless it is used for phonegap. That would certainly explain why you are having problems.

Phonegap is pretty easy to use. Here are the steps.

  1. Sign up for an account on https://build.phonegap.com/
  2. Zip up your www directory (zip -r project.zip www).
  3. Upload it to build.phonegap.com and compile.
  4. Use the QR code (or URI) to download it to your device.

For Apple devices you will need the usual Apple ID stuff.

I am going to check into why the project does not work without phonegap.

@jlinoff
Copy link
Owner

jlinoff commented Aug 12, 2014

I am not sure if this is interesting to you but I just figured out how to get the barcode scanner working in emulation mode under android. Here are the steps.

  1. Install the Android SDK and tools.
  2. Create an AVD (android virtual device) using the "android" command.
  3. List the available avds using "android list avd"
  4. Update your path to include the tools and platform-tools directories from the SDK.
  5. Build the android platform (ionic build android).
  6. Install the APK using the "adb install " command where is the absolute path to the PgBarcodeScanner-debug-unaligned.apk.
  7. Run the emulator with the camera enabled: emulator64-arm -camera-front webcam0 @gn1
  8. When finished remove the APK, if you don't need it anymore: "adb uninstall ".

I verified that it is working (using a newer version).

@marcwhitbread
Copy link
Author

Good news. I've actually got it working now. I wrote a service that seemed to work. I think there might be an error in your service that is preventing it from working on iOS for some reason. I can't be sure though.

Here's my code. I used the same defer/resolve as your service.

app.service('scanService', function($q) {

    /* public */

    return({
        scan: scan
    });

    function scan() {

        // The plugin operates asynchronously so a promise
        // must be used to display the results correctly.
        var deferred = $q.defer();
        var scanner = cordova.require("cordova/plugin/BarcodeScanner");

        scanner.scan(function(result) { 
            deferred.resolve({'error':false, 'result': result});
        }, function(error) {
            deferred.resolve({'error':true, 'result': error.toString()});
        });

        return deferred.promise;

    }

});

@jlinoff
Copy link
Owner

jlinoff commented Aug 17, 2014

That is excellent.

Thank you Marc, I really appreciate your help. I will update with your changes and test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants