Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading NfcNdefData on iOS throws Exception #76

Open
BikeBr0 opened this issue Nov 24, 2021 · 0 comments
Open

Reading NfcNdefData on iOS throws Exception #76

BikeBr0 opened this issue Nov 24, 2021 · 0 comments

Comments

@BikeBr0
Copy link

BikeBr0 commented Nov 24, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant