NeutrinosPlatform / cordova-plugin-document-scanner

cordova plugin for document scan
https://www.neutrinos.co/
MIT License
85 stars 60 forks source link

scan is undefined #28

Closed vofili closed 6 years ago

vofili commented 6 years ago

I integrated the plugin on cordova and cannot find the scan object. I keep getting undefined undefined", source: file:///android_asset/www/index.html (37) [INFO:CONSOLE(38)] "window plugins scan", source: file:///android_asset/www/index.html (38) [INFO:CONSOLE(39)] "undefined", source: file:///android_asset/www/index.html (39) [INFO:CONSOLE(40)] "window Scan", source: file:///android_asset/www/index.html (40) [INFO:CONSOLE(41)] "undefined", source: file:///android_asset/www/index.html (41) [INFO:CONSOLE(42)] "navigator.scan", source: file:///android_asset/www/index.html (42

ChrisTomAlx commented 6 years ago

Hey @vofili

Can you show me the code you used. You don't need to use it as navigator.scan. You can directly use scan.

You can try this in console after just adding the plugin and running the cordova app on an android device then going into google chrome and type in chrome://inspect/#devices into the search bar then press enter. Here you will see your app under which there will be an inspect button you can click. On click a new window opens with a console. Try typing in scan and it should autofill if everything is working correctly.

Cheers, Chris Neutrinos

Karanveer-logiciel commented 6 years ago

@ChrisTomAlx - I am also facing same issue, scan scan is not defined i have already added plugin. But it's only in Android in iOS it's working very well..

ChrisTomAlx commented 6 years ago

@Karanveer-logiciel please could you show me your code?

Cheers, Chris Neutrinos

Karanveer-logiciel commented 6 years ago

yeah sure

Karanveer-logiciel commented 6 years ago

@ChrisTomAlx - Here you can see...


scan.scanDoc(0, function(imageURI) { console.log(imageURI); });

ChrisTomAlx commented 6 years ago

Could you try this instead and see if it works?

scan.scanDoc(0, onSuccess, onFail);

function onSuccess(imageURI) {
    console.log(imageURI);
}

function onFail(message) {
    alert('Failed because: ' + message);
}

Cheers, Chris Neutrinos

ChrisTomAlx commented 6 years ago

@Karanveer-logiciel && @vofili What android version are you using. Is it Android Oreo? If so please use the fix that has been provided in the readme file under issues and fixes.

By the way, @Karanveer-logiciel , I tried your code and my code, both are working fine. Are you using the function before the device ready event? If that is the case it won't work. If you could create a new test app with this plugin and your code and you send it to me. I will test on my end and see what might be the problem.

Cheers, Chris Neutrinos

vofili commented 6 years ago

Hi @ChrisTomAlx

Here is my code

document.addEventListener("deviceready", onScanDeviceReady, false);
        function onScanDeviceReady() {
            Scan.scanDoc(sourceType, successCallback, errorCallback);
        }
        function successCallback(imageData){
            console.log("picture taken - ",imageData);
            localStorage.setItem("chequefrontpicture",imageData);
              var image = document.getElementById('imagechequefrontpicture');
            image.src = "data:image/jpeg;base64," + imageData;

        }
        function errorCallback(error){
                localStorage.setItem("imagedata","");
                console.log("error picture taken - ",error);
        }

i have used this line scan.scanDoc(sourceType, successCallback, errorCallback); and this line

Scan.scanDoc(sourceType, successCallback, errorCallback);

both returned

scan is undefined

Karanveer-logiciel commented 6 years ago

@ChrisTomAlx - I tried both ways as you told but not working for me and i am using after device ready also...

ChrisTomAlx commented 6 years ago

Hey @vofili ,

Okay three things I noticed

var app = {
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    onDeviceReady: function() {
        this.receivedEvent('deviceready');
        //device ready received
        scan.scanDoc(0, onSuccess, onFail);

        function onSuccess(imageURI) {
             console.log(imageURI);
         }

         function onFail(message) {
             alert('Failed because: ' + message);
         }
    },

    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    }
};

app.initialize();

Cheers, Chris Neutrinos

ChrisTomAlx commented 6 years ago

Hey @Karanveer-logiciel

Unfortunately, I will need more information to help you. The best thing you can do is create a new app with the plugin and your code. Make sure it isn't working in yours then send it over to me and I will test if it is working on my end. If it is we can find our way out from there./

Cheers, Chris Neutrinos

Karanveer-logiciel commented 6 years ago

@ChrisTomAlx - FYI i am using CORDOVA CLI -> 6.5.0

Karanveer-logiciel commented 6 years ago

@ChrisTomAlx - Can you help me to find this plugin in platform folder may it will be helpfull for me

ChrisTomAlx commented 6 years ago

@Karanveer-logiciel You definitely need cordova 7.1.0+ and cordova android 6.4.0+ for this to work.

Cheers, Chris Neutrinos

vofili commented 6 years ago

Im using Cordova v7.1.0 and android v 7.1.0

screen shot 2018-08-01 at 1 58 55 pm
vofili commented 6 years ago

okay @ChrisTomAlx

I upgraded my platform android

ionic cordova platform add android@7.1.0

and now i can use the scan object.

I am also able to call scanDoc

Thank you.. You're a legend..

ChrisTomAlx commented 6 years ago

@vofili Great news. Hope you have fun with the plugin. Next time someone asks I should probably start by asking their cordova version. Lesson learned. :)

Cheers and have a nice day, Chris Neutrinos

ChrisTomAlx commented 6 years ago

@Karanveer-logiciel

You can find the java files of the plugin here :- platforms\android\app\src\main\java\com\neutrinos\plugin

and the js files here :- \platforms\android\app\src\main\assets\www\js

I am closing this issue for now, since it seems upgrading to cordova version 7.1.0+ should solve this issue for you as well. Sorry I couldn't be of more help.

Cheers, Chris Neutrinos

Maroshman commented 2 years ago

Hi, I'm having the same problem. "Uncaught ReferenceError: Scan is not defined" I'm using cordova and cordova android platform 11.0.0