2

I have a problem in a function PhoneGap-NFC plug-in Intel XDK.

function nova_pulseira(cli_nova_id) {
    nfc.addTagDiscoveredListener(function (nfcEvent) {
        var tag = nfcEvent.tag;
        var = TagID nfc.bytesToHexString(tag.id);

        if(TagID! == 0) {
            nova_pulseira_input(cli_nova_id, TagID);
        } else {
            myApp.alert( 'error in reading the bracelet.' 'Notice');
        }
    });
}

The nfc.addTagDiscoveredListener function is used for reading NFC TAG when occurs nfcEvent.
In the first reading it works normally, but when make the second reading, the nfc.addTagDiscoveredListener function is applied two times, the third reading, it is applied 3 times, and so on.
The only way I found to "stop" this function is using location.reload(); but he returns to the Application home page, and the ideal would be to activate a subpage.
I would, somehow, that nfc.addTagDiscoveredListener function is disabled after applying the nova_pulseira_input(cli_nova_id, TagID); function.
PS: I've used
-> Return false;
-> $ .each (Nfc, function () {this.reset ();});
-> Intel.xdk.cache.clearAllCookies ();
-> $ .ajaxSetup ({Cache: false});

Thanks for the help of all ...

xmnboy
  • 2,314
  • 2
  • 14
  • 31
  • I recommend you make a simpler event handler that generates console.log() messages and prints the object information you receive. Avoid using an alert to debug the issue. Alerts can interfere with normal processing and cause difficult to diagnose problems. – xmnboy Sep 13 '16 at 01:05

1 Answers1

0

Put the function inside a var and redefine it later:

var tagHandler = function () {
        handlerOk();
 };
    
function handlerOk () {
  console.log("handlerOk()");
  tagHandler = function() {
   console.log("disabled..")
  };
}

function tag() {
    console.log("tag()");
    tagHandler();
}

tag();
tag();
Marcio J
  • 673
  • 7
  • 17