chariotsolutions / phonegap-nfc

PhoneGap NFC Plugin
MIT License
706 stars 556 forks source link

[iOS] Ready to scan, but nothing happen #351

Closed juliengloria closed 5 years ago

juliengloria commented 5 years ago

Hi, I got the flyout "Ready to Scan" on my phone, but nothing is raised in my subscription.

     this.nfc.beginSession().subscribe(() => {
          console.log('successfully beginSession');
          this.messages.push('successfully beginSession');
          this.nfc.addNdefListener(() => {
            console.log('successfully attached ndef listener');
            this.messages.push('successfully attached ndef listener');
            this.cekNFC();
          }, (err) => {
            console.log('error attaching ndef listener' + err);
            this.messages.push('error attaching ndef listener' + err);
          }).subscribe((event) => {
            console.log('received ndef message. the tag contains: ' + event);
            this.messages.push('received ndef message. the tag contains:' + event);

          });
        });
      } catch (error) {
        console.log('error ' + error);
      }
    }); 
phyr0s commented 5 years ago

Separat the NFC beginSession

function enableNFC() { nfc.beginSession(); } When you init the NFC you will see one popOver on your iphone.

Later add your code -->

nfc.addNdefListener(() => { console.log('successfully attached ndef listener'); this.messages.push('successfully attached ndef listener'); this.cekNFC(); }, (err) => { console.log('error attaching ndef listener' + err); this.messages.push('error attaching ndef listener' + err); }).subscribe((event) => { console.log('received ndef message. the tag contains: ' + event); this.messages.push('received ndef message. the tag contains:' + event); });

nfc is GLOBAL so is not on THIS context....

declare let nfc : any; at top of constructor

don commented 5 years ago

Does your NFC tag contain an NDEF message? iOS only scans NDEF tags.

You could try this sample project https://github.com/don/phonegap-nfc-ios