我想读取带有phonegap nfc(Tutorial phonegap)的nfc卡,但事件未启动
这是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));
    }
);
},

有什么建议吗?

最佳答案

用nfc.addTagDiscoveredListener而不是nfc.addndefListener解决

10-05 21:07
查看更多