2016-03-15 100 views
1

我想讀NFC卡與PhoneGap的NFC(Tutorial phonegap),但該事件沒有啓動NFC閱讀器的Apache Cordova

這是index.js

onDeviceReady: function() { 
    app.receivedEvent('deviceready'); 

// Read NDEF formatted NFC Tags 
nfc.addNdefListener (
    function (nfcEvent) { 
     var tag = nfcEvent.tag, 
      ndefMessage = tag.ndefMessage; 

     // dump the raw json of the message 
     // note: real code will need to decode 
     // the payload from each record 
     alert(JSON.stringify(ndefMessage)); 

     // assuming the first record in the message has 
     // a payload that can be converted to a string. 
     alert(nfc.bytesToString(ndefMessage[0].payload).substring(3)); 
    }, 
    function() { // success callback 
     alert("Waiting for NDEF tag"); 
    }, 
    function (error) { // error callback 
     alert("Error adding NDEF listener " + JSON.stringify(error)); 
    } 
); 
}, 

任何建議的代碼?

+0

解決的,你想閱讀與應用程序打開?你有任何輸出在控制檯或警報? – Del

回答

3

nfc.addTagDiscoveredListener,而不是nfc.addNdefListener