Twitter bootstrap Cordova nfc插件将文本写入nfc卡
我正在使用cordova进行测试,以便将简单文本写入卡。我有一个引导按钮Twitter bootstrap Cordova nfc插件将文本写入nfc卡,twitter-bootstrap,cordova,nfc,Twitter Bootstrap,Cordova,Nfc,我正在使用cordova进行测试,以便将简单文本写入卡。我有一个引导按钮 onclick="write_btn();" 在index.js中,我添加了 function write_btn(){ alert("Write some to card"); var message = [ ndef.textRecord("hello, world of NFC"), ]; var sMsg; nfc.write(message, f
onclick="write_btn();"
在index.js中,我添加了
function write_btn(){
alert("Write some to card");
var message = [
ndef.textRecord("hello, world of NFC"),
];
var sMsg;
nfc.write(message,
function(){sMsg="good";alert("Write Succes");},
function(){sMsg="fals";alert("Nothing got written");}
);
console.log("Writing is: "+sMsg);
alert("Writing is: "+sMsg);
}
但是没有写任何东西,只有警报。如果函数write_btn中只有警报(“…”),则会触发该警报。ndef是一个全球风险值,对吗
在Android上,当NFC标签在手机范围内时,您需要呼叫ndef.write(消息)。最好的方法是从nfcEvent处理程序内部调用write
# www/js/index.js
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
nfc.addNdefListener(app.onNfc);
},
onNfc: function(nfcEvent) {
// message is an array of records
var message = [
ndef.textRecord("hello, world")
];
nfc.write(message, app.onWriteSuccess);
},
onWriteSuccess: function() {
alert("Wrote message to tag.");
}
};
你明白了吗?