Skip to content

NFC Tag Writing Issue #494

Description

@bevinGithub

Hi guys l need your assistance please. I have NFC reading and writing on my app. The reading is fine it's the writing part that is an issue. If l start my app and proceed to go to writing to tags and the tag writing works but if l navigate to the previous page and go back to the writing page the tag writing when you try to write to tag it keep on giving a success message but it's not writing to the tag. I have to restart the app for the tag writing to function again.

Is there something that l am not switching of from the tag or is there something hanging when l navigate to the page.

Any assistance or pointing me in the right direction will be much appreciated.

Writing Function Code below
writeTag(tagData) {
this.writeDate = moment().format('DD-MM-YYYY HH:mm:ss');
this.tag = tagData?.item;
console.log(this.tag);
this.platform.ready().then(() => {
this.writingTag = true;
this.listener = this.nfc.addNdefListener((res: any) => {
console.log('Listener is Active: ' + res);
}, (error) => {
this.presentToast(error);
}).subscribe(() => {
const referenceNumber = this.ndef.textRecord(this.tag?.reference_number);
const date = this.ndef.textRecord(this.writeDate);

    this.nfc.write([referenceNumber, date]).then(success => {
      alert(JSON.stringify(success));
      if (success === 'OK') {
        this.listener.unsubscribe();
        this.presentToast('Successfully written to RFID Tag!');
      } else {
        this.presentToast('Could not write to tag sucessfully!');
      }
    }).catch(error => {
        if (error === null) {
          this.presentToast('Tag could not be written!');
        }
        if (error === 'Only one Tag Technology can be connected at a time.') {
          this.presentToast('Failed to write to tag sucessfully, please try again!');
        }
      });
  }, err => {
    this.presentToast(JSON.stringify(err));
  });
});

}

My environment information
Ionic:

Ionic CLI : 6.20.1 (C:\Users\Tigere Bervin\AppData\Roaming\npm\node_modules@ionic\cli)
Ionic Framework : @ionic/angular 6.7.5
@angular-devkit/build-angular : 13.0.4
@angular-devkit/schematics : 13.0.4
@angular/cli : 13.0.4
@ionic/angular-toolkit : 5.0.3

Cordova:

Cordova CLI : 11.0.0
Cordova Platforms : android 12.0.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 14 other plugins)

Utility:

cordova-res : 0.15.4
native-run (update available: 1.7.3) : 1.7.2

System:

Android SDK Tools : 26.1.1 (C:\Users\Tigere Bervin\AppData\Local\Android\Sdk)
NodeJS : v16.14.0 (C:\Program Files\nodejs\node.exe)
npm : 8.3.1
OS : Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions