简体   繁体   English

NFC阅读器Apache Cordova

[英]NFC reader apache cordova

I want to read nfc card with phonegap nfc ( Tutorial phonegap ) but the event is not launched 我想用phonegap nfc( 教程phonegap )读取nfc卡,但该事件未启动

this is the code of the index.js 这是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));
    }
);
},

Any suggestion ? 有什么建议吗?

使用nfc.addTagDiscoveredListener而不是nfc.addNdefListener解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM