2012-08-02 7 views
3

Android 앱에서 PhoneGap Plugin Barcode Scanner를 사용했습니다. window.plugins.barcodeScanner.encodewindow.plugins.barcodeScanner.scan은 버튼에 onclick 이벤트를 첨부 할 때 완벽하게 작동합니다. 내가 몸/페이지 초기화/페이지 쇼 이벤트의 onload 이벤트에 인 코드 기능을 실행하려고 할 때, 나는 바코드 스캐너 - Cordova Plugin

Uncaught TypeError: Cannot call method 'encode' of undefined at file:///android_asset/www/indexx.html:32 

이클립스

에서 오류 다음 얻을 그러나

은 .. 감사

답변

0

Cordova가 로딩을 마친 후 (메소드 이벤트) 메소드를 호출하십시오.

2

어떤 phonegap 버전을 사용하고 있습니까? 1.9.0 또는 2.0.0?

2.0.0에는 플러그인을 호출하는 새로운 방법이 있습니다. 1.9에 다음을 사용 :

window.plugins.barcodeScanner.scan(function(result) { 
    ... 
    .. 
} 

당신이 2.0.0을 사용하는 경우는, 플러그인 초기화 다른 방법으로 시도 :에 따라

window.barcodeScanner = new BarcodeScanner(); 

function scanBarcode() 
{ 
    window.barcodeScanner.scan(function(result) { 
     alert("We got a barcode\n" + 
       "Result: " + result.text + "\n" + 
       "Format: " + result.format); 
    }, function(error) { 
     alert("Error scanning Barcode: " + error); 
    }); 
} 
0

나는 코르도바에 새로운 오전,하지만 내가 @traumalles처럼 들리네. 코르도바는로드가 완료된 후 window.plugins.barcodeScanner.encode 또는 window.plugins.barcodeScanner.scan 함수를 호출하려면 자바 스크립트 파일에서 다음을 수행하십시오

// Wait for Cordova to load 
document.addEventListener("deviceready", onDeviceReady, false); 

// Cordova is ready 
function onDeviceReady() { 
    // As an example, you now have the device name, Cordova version, etc. available 
    alert('Device Name: ' + device.name); 
    alert('Device Cordova: ' + device.cordova); 
    alert('Device Platform: ' + device.platform); 
    alert('Device UUID: ' + device.uuid); 
    alert('Device Version: ' + device.version); 

    // Now call one of your barcode functions, etc. 
} 

자세한 내용은 http://docs.phonegap.com/en/2.0.0/cordova_device_device.md.html#Device를 참조하십시오.