chariotsolutions / phonegap-nfc

PhoneGap NFC Plugin
MIT License
706 stars 557 forks source link

Can't read tags when open App (but, it read them when re-open my app) #216

Closed portal64 closed 6 years ago

portal64 commented 8 years ago

Hi, I have a weird problem, and I can't solve it..

When I open my app, and read a NFC tag in my mobile, its sounds but not execute my callback function. Next, I press the "Recents apps" button in my Nexus 5, and reopen again my app (resume). Now, when I read the same NFC tag again, it works perfectly.

This is my code:

document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
    nfc.addTagDiscoveredListener(onNfc, winNfc, failNfc);
...
}

 function onNfc(nfcEvent) { // I only want to read the tag Identifier

        alert('onNFC');

        var tag = nfcEvent.tag;
        var tagId = nfc.bytesToHexString(tag.id);
        alert(tagId);

...
}

    function winNfc() {
        console.log("Listening for NFC Tags");
    }

    function failNfc(error) {
        alert("Error de NFC: " + error);
    }

I use build.phonegap.com to compile, and have this line in my config.xml:

<gap:plugin name="com.chariotsolutions.nfc.plugin"  />

Phonegap version: 3.5.0

What I am doing wrong ??

THANKS in advance.

Raúl.

don commented 8 years ago

Try using the latest version of the plugin in config.xml

<gap:plugin name="phonegap-nfc" source="npm" />

The code you posted looks OK. I'd expect there's a JavaScript error somewhere. Can you share your code?