【发布时间】:2020-11-16 12:46:41
【问题描述】:
我想用 Phonegap 读取 NFC 卡,但代码不起作用。 该代码正在读取公共交通卡或健身卡的 NFC 卡(并且运行良好),但它不读取银行卡。 当我尝试读取所有银行卡时,似乎 NFC 根本没有读取它。我得到一个带有文本的白屏:“标签为空或电话未对齐”。它接缝该应用程序无法识别银行卡。
var app = { initialize: function() { this.bindEvents(); }, bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); }, onDeviceReady: function() { app.receivedEvent('deviceready'); var success = function() { console.log("Listening for formatable NFC tags"); }; var failure = function(reason) { console.log("Error adding NFC listener " + reason); }; nfc.addNdefFormatableListener(app.onNfc, success, failure); }, onNfc: function(nfcEvent) { // display the tag as JSON alert(JSON.stringify(nfcEvent.tag)); var success = function() { alert("Wrote data to tag"); }; var failure = function(reason) { alert("NFC write failed " + reason); }; var message = [ ndef.uriRecord("http://www.amazon.com/dp/1457187094") ]; nfc.write(message, success, failure); }, // Update DOM on a Received Event receivedEvent: function(id) { var parentElement = document.getElementById(id); var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received'); listeningElement.setAttribute('style', 'display:none;'); receivedElement.setAttribute('style', 'display:block;'); console.log('Received Event: ' + id); } }; app.initialize();
【问题讨论】:
标签: javascript cordova cordova-plugins nfc phonegap