使用nativescript-nfc插件创建Nativescript-vue应用。我有以下内容:
<script>
const applicationSettings = require("application-settings");
var Nfc = require("nativescript-nfc").Nfc;
export default {
methods: {
onButtonTap() {
if (this.nfcEnabled) {
this.nfc
.setOnNdefDiscoveredListener(
data => {
if (data.message) {
data.message.forEach(record => {
console.log("Scanner:NdefListener=" + record.payloadAsString);
this.nfcLastTagRead = record.payloadAsString;
if (this.nfcLastTagRead) {
let fob = fobService.findFob(this.this.nfcLastTagRead);
console.log(
"found "this.this.nfcLastTagRead);
} else {
console.log("nfcLastTagRead is falsy");
}
});
}
},
{
stopAfterFirstRead: true
}
)
.then(() => {
console.log("Scanner:setStartNdefListener added");
})
.catch(err => console.err(err));
} else {
console.log("NFC is not enabled or available on this device");
}
},
lookupId: function() {
console.log("in the lookupId()");
}
},
data() {
return {
nfc: null,
nfcEnabled: false,
nfcLastTagRead: ""
};
},
beforeMount: function() {
const uuid = applicationSettings.getString("deviceId");
// instantiate the plugin
this.nfc = new Nfc();
this.nfc
.available()
.then(available => {
console.log("Scanner:available=" + available);
return this.nfc.enabled();
})
.then(enabled => {
console.log("Scanner:enabled=" + enabled);
this.nfcEnabled = true;
})
.catch(err => console.err(err));
}
};
</script>
在启动时并单击click()时运行此命令,我在控制台中得到以下内容:
控制台日志文件:///app/bundle.js:377:18: \ 134 ^ [[32m'Scanner:available = true'\ 134 ^ [[39m CONSOLE LOG 文件:///app/bundle.js:380:18: \ 134 ^ [[32m'Scanner:enabled = true'\ 134 ^ [[39m HTHangEventCreate: HangTracing已禁用。不创建新事件。
我看到NFC插件确实可以工作,但是在消息出现后似乎停止了。在搜索此特定错误消息时,所有结果都指向Firebase的插件问题,但是我没有在项目中使用它,也没有任何依赖项。