EddyVerbruggen / nativescript-nfc

:pencil: NativeScript plugin to discover, read, and write NFC tags
MIT License
84 stars 37 forks source link

Reading NfcNdefData on iOS throws Exception #76

Open BikeBr0 opened 2 years ago

BikeBr0 commented 2 years ago

Steps to reproduce:

  1. On a Mac using NativeScript CLI 8.1.4 create a new Hello World Angular project
  2. Add app.entitlements and NFCReaderUsageDescription as instructed
  3. Add the nativescript-nfc plugin
  4. Place the following code into ngOnInit in item-detail.component.ts:

`

let nfc = new Nfc();
nfc.available().then(avail => {
  console.log(avail ? "NFC is enabled" : "NFC is disabled");
});

nfc
  .setOnNdefDiscoveredListener(
    (data: NfcNdefData) => {
      // data.message is an array of records, so:
      if (data.message) {
        for (let m in data.message) {
          let record = data.message[m];
          console.log(
            "Ndef discovered! Message record: " + record.payloadAsString
          );
        }
      }
    },
    {
      // iOS-specific options
      stopAfterFirstRead: true,
      scanHint: "Scan a tag, baby!"
    }
  )
  .then(() => {
    console.log("OnNdefDiscovered listener added");
  });

`

This code works on Android when tapping an NFC dongle (i.e. "Ndef discovered! Message record: Test" is printed to the console) but on iOS, I get:

CONSOLE LOG: NFC is enabled CONSOLE LOG: OnNdefDiscovered listener added iPhone nfctest(Foundation)[72883] : <NSXPCConnection: 0x282864fa0> connection to service with pid 60 named com.apple.nfcd.service.corenfc: Exception caught during decoding of received selector didDetectExternalReaderWithNotification:, dropping incoming message. Exception: Exception while decoding argument 0 (#2 of invocation): Exception: decodeObjectForKey: class "NFFieldNotification" not loaded or does not exist

I am running iOS 15.0.2 on an iPhone 11 and I have confirmed the App has NFC Tag Reading for the App ID.