离子事件侦听器(addListenNFC)控件

时间:2018-08-10 06:37:17

标签: javascript typescript ionic-framework ionic2 ionic3

我现在正在开发Ionic 2应用程序,并且我在项目中使用NFC模块。通常,我想使用nfclistener读取nfc标签ID,然后通过Web套接字发送ID,但是侦听器多次读取nfc标签一次读取操作,因此Web套接字函数发送许多次相同的值。

如何控制每次读取一次发送ID的NFClistener动作。

我的收听者代码:

addListenNFC() {

this.nfc.addTagDiscoveredListener(nfcEvent => this.sesReadNFC(nfcEvent.tag)).subscribe(data => {
  if (data && data.tag && data.tag.id) {
    let tagId = this.nfc.bytesToHexString(data.tag.id);
    if (tagId) {
      this.tagId = tagId;
      this.scanned = true;

      // only testing data consider to ask web api for access
        if( this.tagId == "0476d05aa84a81"){

          this.widgetNfc();

        }else if(this.tagId == "0478d25aa84a81"){

          this.widgetNfc1();

        }
      this.granted = [
        "7d3c6179"
      ].indexOf(tagId) != -1;

    } else {

      alert('NFC_NOT_DETECTED');
    }
  }
});
}

0 个答案:

没有答案