3

I've been adding code to my new Vf page from @bob-buzzard blog (http://bobbuzz.me.uk/1fJ12Xw) to read QR codes from Salesforce1. i've tested on chrome web browser and i have not had any problem.. but on my iphone 5s i can't run it as should be.

Any idea to resize the image or something to avoid error on Mobile Salesforce1 enviroment?

The code is shown below (utilize jsqrcodelibrary as shown bob's post):

<script type="text/javascript">
    function read(a)
    {
          alert(a);
          if( (typeof sforce != 'undefined') && (sforce != null) ) {
              //sforce.one.navigateToSObject(a);
          }
          else {
              //window.location="/" + a;
          }
    }

    $(document).ready(function() {
          qrcode.maxImgSize = 700*700;   <----------------- I tried to do this.
          qrcode.callback = read;

    });

    function previewFile() {
      var preview = document.querySelector('#preview');
      var file    = document.querySelector('input[type=file]').files[0];
      var reader  = new FileReader();

      reader.onloadend = function (file) {
         preview.src = reader.result;
      }

      if (file) {
        console.log('File: '+ file);
        reader.readAsDataURL(file);
      } else {
        preview.src = "";  
      }
    }

    function decode() {
        try
        {
        var preview = document.querySelector('#preview');
        qrcode.decode(preview.src);
        }
        catch (e)
        {
           alert('Error - ' + e.message);
        }
   }
</script>

<form>
  <input type="file" accept="image/*" onchange="previewFile()"/>
 <h1>Vista Previa</h1>
 <div style="height:200px">
  <img id="preview" height="200" alt="Imagen vista previa..." />
 </div>
</form>
<button id="decode" onclick="decode()">Decodificar</button>
</apex:page>

Everything seems correct on web enviroment but i didn't find any solution and can't figure out why the error "Error decoding QR Code" on salesforce1 despite that tried to debug and log everything.

Any idea how to fix this? Or anyone was working with this? Thanks in advance

9

This is actually a known issue with the jsqrcode library. It is logged as a known issue (decoding failing on iOS devices) here and the workaround is listed in the same thread. I tried it and it worked well for me. You can also find more details on the iOS specific bug here.

The fix is essentially to

In qrcode.js, add the two stackoverflow functions

  • detectVerticalSquash(),
  • drawImageIOSFix()

Replace in qrcode.decode (in qrcode.js)

context.drawImage(image, 0, 0, canvas_qr.width, canvas_qr.height );

with

drawImageIOSFix(context, image, 0, 0, image.width, image.height, 0, 0, nwidth, nheight);"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.