I can't get BarcodeScanner to work


#1

Hello Everybody, I was wondering if anyone knew how to make BarcodeScanner work. Can’t make it work with the documentation provided by this page nor GitHub.


#2

Are you trying with ionic 2 ?


#3

Yes, this is what I tried to encode:
BarcodeScanner.encode (BarcodeScanner.Encode.TEXT_TYPE, 'hello world', function (success) { alert ('encode success: ' + success); }, function (fail) { alert ('encode fail: ' + fail); }); return tablRef.key; }

And this is what I tried to scan:
BarcodeScanner.scan (function (success) { console.log (success); }, function (fail) { console.log (fail); }); }

I get this error in both of them

supplied parameters do not match any signature of call target.

Really don’t know what to do.


#4

If you’re building an Ionic2 project, why do you still use ‘old’ javascript syntax? I suppose I would try it with fat arrow syntax, since it handles scopes quite differently. Don’t know if it’s related to the fact why it isn’t working for you, but I guess you should give that a try.

update: If I’m looking at the documentation for ionic2 barcode scanner wrapper, I see some entirely different code examples. What kind of Ionic project are you running?


#5

You genius! Thank you very much. The at least the .scan() is working.

I am having problems with the BarcodeScanner.encode() now. I am not sure how to:

  1. Make it a QR_CODE
  2. Display the QR_CODE.

I changed my code a little bit. Now it’s like this:

BarcodeScanner.encode (BarcodeScanner.Encode.TEXT_TYPE,
      'asdf')
        .then ((suc) => {
          // don't know what to do here
        }), (err) => {
          // don't know what to do here
        }

Do you know what to do?

Thanks a lot!


#6

I figured the answer.

What I had to do is to declare a property inside my class. For me it’s called urlImage. Then, inside the encode function:

BarcodeScanner.encode (BarcodeScanner.Encode.TEXT_TYPE, 'Hello World')
  .then ((success) => {
    this.urlImage = success.file;
  }), (error) => {
    alert (error);
  }

Then, in my html code:

<img src="{{urlImage}}">

And that’s it.


#7

I guess everyone knows what you mean but lets correct it since there is a typo in your handlebar expression

<img src="{{urlImage}}"/>

#8

You don’t need the slash inside <img> tags in HTML5.


#9

Thanks, I’ll fix it right now.