javascript - NFC reader apache cordova - Stack Overflow

I want to read nfc card with phonegap nfc ( Tutorial phonegap ) but the event is not launchedthis is th

I want to read nfc card with phonegap nfc ( Tutorial phonegap ) but the event is not launched

this is the code of the 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 ?

I want to read nfc card with phonegap nfc ( Tutorial phonegap ) but the event is not launched

this is the code of the 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 ?

Share Improve this question asked Mar 15, 2016 at 8:30 user40101121user40101121 1672 silver badges9 bronze badges 1
  • Are you trying to read with the app opened? Do you have any output in the console or alerts? – Víctor Commented Mar 15, 2016 at 8:50
Add a ment  | 

1 Answer 1

Reset to default 5

Solved with nfc.addTagDiscoveredListener instead of nfc.addNdefListener

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745241237a4618193.html

相关推荐

  • javascript - NFC reader apache cordova - Stack Overflow

    I want to read nfc card with phonegap nfc ( Tutorial phonegap ) but the event is not launchedthis is th

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信