chariotsolutions / phonegap-nfc

PhoneGap NFC Plugin
MIT License
706 stars 555 forks source link

ERROR: Method 'registerTag:' not defined in Plugin 'NfcPlugin' #370

Closed dewald-els closed 4 years ago

dewald-els commented 4 years ago

I've been trying to get this working on iOS with no luck. I call the beginSession() function before attempting to start the scan.

The console throws out the following error:

ERROR: Method 'registerTag:' not defined in Plugin 'NfcPlugin'
2019-08-18 19:20:27.952211+0200 Tickipay for promoters[1522:361428] FAILED pluginJSON = ["NfcPlugin26458284","NfcPlugin","registerTag",[]]
2019-08-18 19:20:36.289504+0200 Tickipay for

Here is a sample of the code:

if (this.currentPlatform === 'ios') {
            await this.nfc.beginSession().toPromise();
            this.scanner$ = this.nfc.addNdefListener(() => {
                this.status = 'Scanner Ready...';
            }, () => {
                this.status = 'Failed to initialize scanner.';
            }).subscribe((e) => {
                this.tagDiscovered(e);
            })
        } else {
            this.scanner$ = this.nfc.addTagDiscoveredListener(() => {
                this.status = 'Scanner Ready...';
            }, () => {
                this.status = 'Failed to initialize scanner.';
            }).subscribe((e) => {
                this.tagDiscovered(e);
            });
        }

Any help would be greatly appreciated!

AtanasChachev commented 4 years ago

I also receive this error when using addTagDiscoveredListener for iOS. From the CoreNFC documentation provided by apple:

NFCTagReaderSession A reader session for detecting ISO7816, ISO15693, FeliCa, and MIFARE tags.

and

NFCVASReaderSession A reader session for processing Value Added Service (VAS) tags.

are still in Beta and will be available within iOS 13. So the solution is wait for iOS 13 release and then some good soul to add support for addTagDiscoveredListener for iOS.

EDIT:

Otherwise if you want to listen only NDEF tags to iOS I do use the following code with @ionic-native/nfc and it works perfectly.

import { NFC } from '@ionic-native/nfc';
...
constructor(private nfc: NFC) {...}
...
enableNFC(): void {
 this.nfc.enabled().then(() => {
      this.subscribers.nfcSession = this.nfc.beginSession().subscribe(() => {
        this.subscribers.addListener = this.nfc.addTagDiscoveredListener(() => {}).subscribe((event: any) => {
          alert(this.nfc.bytesToString(event.tag.ndefMessage[0].payload))

          this.subscribers.nfcSession.unsubscribe();
          this.subscribers.addListener.unsubscribe();
        });
      });
    }, () => {
      alert('NFC NOT ALLOWED');
    });
}
don commented 4 years ago

Also see https://github.com/don/phonegap-nfc-ios

don commented 4 years ago

iOS works in v1.1.0. addTagDiscoveredListener is not supported on iOS.