chariotsolutions / phonegap-nfc

PhoneGap NFC Plugin
MIT License
706 stars 556 forks source link

ionic and nfc not reading tags #268

Closed r4mst3r closed 6 years ago

r4mst3r commented 7 years ago

Hi, I just pulled this plugin (v 0.6.6) for a nfc enabled ionic 1 application on my android onplus 3t phone.

I can hear the foreground of the nfc service on my phone making the sound and recognizing the tag but my app does not recognize it. I downloaded the ionic-nfc-reader demo and that too does not read tags.

however my phone does auto detection to the tags and I downloaded NFC tools app from playstore and that too can read the tag im trying to get my app (and ionic nfc reader demo) to read.

here is my code:

in my controller()

    nfc.addNdefListener($scope.onNfc, $scope.onNfcSuccess, $scope.onNfcFail);
    nfc.addNdefFormatableListener($scope.onNfc, $scope.onNfcSuccess, $scope.onNfcFail);
    nfc.addTagDiscoveredListener($scope.onNfc, $scope.onNfcSuccess, $scope.onNfcFail);
    nfc.addMimeTypeListener('text/plain', $scope.onNfc, $scope.onNfcSuccess, $scope.onNfcFail);

and my callbacks

$scope.onNfc = function( nfcEvent ) { console.log(nfcEvent); // display the tag as JSON alert(JSON.stringify(nfcEvent.tag, null, 4)); }

$scope.onNfcSuccess = function (result)
{
    alert('NFC listening');
}

$scope.onNfcFail = function (result) {
    alert( 'NFC failed: ' + result );
}

im just trying to get the callbacks to fire but it doesnt seem to be firing at all!

don commented 6 years ago

Ionic is awesome but adds a lot of complexity. I find it's best to make sure the simplest cases work them move to debugging Ionic.

Create a new NDEF tag. Download NXP Tag Writer and write a new plain text message to the tag. Follow the Getting Started instructions to make sure you can read the tag without Ionic. Assuming that works, try and read the tag with Ionic NFC Reader.