NFC reading and writing [SOLVED]



does anybody know how to implement writing to NFC correctly in Ionic 2? This following example does write a tag, but if you try to write another one, the app crashes. Tried with two different android mobilephones.

// removed bad code from here. See a working solution below.

If somebody is struggling with the same problem, I think this has something to do with that how the addNdefListener fires multiple times. Maybe couple of if statements will solve this. Troubleshooting continues after the weekend.

1 Like

Okay, I got it finally working. Here is working example for anyone wondering how to use NFC reading and writing in ionic 2. Always remember to unsubscribe NdefListener or it will stay alive even if you close the page.

I removed some parts from this, but here should be working skeleton to work with.

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

// plugins
import { NFC, Ndef } from '@ionic-native/nfc';

import { Subscription } from 'rxjs/Rx'

  selector: 'page-nfc',
  templateUrl: 'nfc.html',
export class NfcPage {

  readingTag:   boolean   = false;
  writingTag:   boolean   = false;
  isWriting:    boolean   = false;
  ndefMsg:      string    = '';
  subscriptions: Array<Subscription> = new Array<Subscription>();

    public navCtrl: NavController,
    public navParams: NavParams,
    public nfc: NFC,
    public ndef: Ndef) {

        .subscribe(data => {
          if (this.readingTag) {
            let payload = data.tag.ndefMessage[0].payload;
            let tagContent = this.nfc.bytesToString(payload).substring(3);
            this.readingTag = false;
            console.log("tag data", tagContent);
          else if (this.writingTag) {
            if (!this.isWriting) {
              this.isWriting = true;
                .then(() => {
                  this.writingTag = false;
                  this.isWriting = false;
                .catch(err => {
                  this.writingTag = false;
                  this.isWriting = false;
        err => {

  ionViewWillLeave() {
    this.subscriptions.forEach(sub => {

  readTag() {
    this.readingTag = true;

  writeTag(writeText: string) {
    this.writingTag = true;
    this.ndefMsg = this.ndef.textRecord(writeText);


This solution is perfect. For me actually i’m using platform ready to initiate the NFC. So it still works :smiley: Thanks twix !

ionViewWillEnter() {
        this.platform.ready().then(() => {

Can you please send the full source code. As I am unable to get you point.


Hi all,
I’m trying to share data between the two nfc devices. I don’t how to do that.Please help with that.


I am trying to figure this out as well


can you post full source code?

Im stuck for weeks with NFC. Simply doens’t work on my real device Samsung S7 Edge.