NFC reading Tag ID

Hello guys,

I want to use the NFC Plugin to get the ID from a Tag. I installed it and implemented the Eventlistener which I need.
To this point everything works. My events trigger like they should and i’m able to read the Tag.

I need the ID in hex and after checking the tag.id I noticed that the id contains only numerical values so i tryed to convert it to hex with .toString(16);.
But then i realised that the id contains negative values which makes me a bit confused. Shouldn’t there be just positive values? Or is that id formatted or encrypted in any way?
When I’m checking the tag with my TagInfo app the ID is a normal Hex Tag-ID.

Sorry if this question is a bit dumb but I’m completly new to NFC and RFID tags and i can’t find any usefull example for reading tags in Ionic2… :confounded:

Would be great if some of you could tell me how to get the right Tag ID. :slight_smile:

Maybe this can help: http://stackoverflow.com/questions/10708614/is-it-possible-to-read-nfc-tag-uid-with-phonegap-how

yeah its working with that!

the problem was/is that you can’t use the Ionic Native NFC because it dosen’t contain all funktions and some of the funktions seem to be broke as well…
So i was in need to use Typings instead to use the Phonegab plugin direktly without Ionic Wrapper

Hi marvin, how did you get it work to detect tags?
I’m trying to integrate it into my Meteor/Ionic2 project but the eventlisteners is not working (trying with console.log for now):

export class AppComponent {
rootPage: any;
public translatedText: string;
public supportedLangs: any[];

constructor(platform: Platform,translate: TranslateService) {
translate.addLangs([“en”]);
translate.setDefaultLang(‘en’);

    // the lang to use, if the lang isn't available, it will use the current loader to get them
translate.use('en'); 
this.rootPage = Meteor.user() ? navComponent : LoginComponent;        

platform.ready().then(() => {
  // Okay, so the platform is ready and our plugins are available.
  // Here you can do any higher level native things you might need.
  

  NFC.addTagDiscoveredListener('text/plain').subscribe(res => {
          console.log("res " + res);
        },(err) => console.log(err));

  StatusBar.styleDefault();
});

}

thanks for your help

Note for readers who came here that have problems with getting the tag ID: You can now use functions that can return hex value for the tag ID: https://github.com/driftyco/ionic-native/pull/853

Now, to answer @tom_it question - we need more info: What exactly does not work? Did you installed phonegap-nfc plugin?
ionic plugin add phonegap-nfc

Which errors do you get?
Try the following function:

NFC.addNdefListener().subscribe(nfcData => {
  console.log("Received NFC tag: " + JSON.stringify(nfcData)); 
});

Hi Cromodder,

Thanks for your code. This works indeed, thanks.
Another question: when leaving the page, using the ngDestroy, I want to remove the nDefListener again. The function removeNdefListener seems not to be included in the NFC ionic-native package.
Is there another way to remove the nDefListener or no solution for this at the moment?

Yeah, there isn’t remove listener in ionic-nativ, but as I am reading now they aren’t even recommended (#118, #234)
So for now I will go with the approach that don suggested:

I think a better approach is to leave the listeners and conditionally ignore the data coming into the listener when you don’t care about it.

I don’t like this idea, but again - don’t really see the other solution.If you find a better way to handle this please let me know.

ok, I have a work-a-round indeed by only applying the listener when you are in the right view.
Thanks for your support, very helpful!