NFC阅读器阿帕奇科尔多瓦

NFC reader apache cordova

本文关键字:阿帕奇 NFC      更新时间:2023-09-26

我想读取带有 phonegap nfc 的 nfc 卡(教程 phonegap ),但活动没有启动

这是索引的代码.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));
    }
);
},

有什么建议吗?

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