I am struggling with my button calling the test2 function and the code I have is not working as expected. Here is what I currently have:
import { Component } from '@angular/core';
import { NFC, Ndef } from '@ionic-native/nfc/ngx';
@Component({
selector: 'app-tab3',
templateUrl: 'tab3.page.html',
styleUrls: ['tab3.page.scss']
})
export class Tab3Page {
constructor( private nfc: NFC, private ndef: Ndef,) {
}
test2(){
this.nfc.addNdefListener(() => {
console.log('successfully attached ndef listener');
}, (err) => {
console.log('error attaching ndef listener', err);
}).subscribe(() => {
console.log("works");
let message = [this.ndef.textRecord("hello, world")];
this.nfc.share(message);
}, err => console.log(err));
}
}
Unfortunately, the subscribe method is not triggered when passing my NFC tag to it, even though the addNdefListener works fine. Can anyone help me troubleshoot this issue?
My setup includes IONIC 5.6 with capacitor, along with the native NFC plugin.
Your assistance would be greatly appreciated. Thank you!