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

Enabling Multiple Uses of NFC requestTechnology Instead of One-time #704

Closed
divashuthron opened this issue Mar 12, 2024 · 4 comments
Closed
Labels

Comments

@divashuthron
Copy link

divashuthron commented Mar 12, 2024

Hello. I am an IT developer working for a small company in Korea.

What I want to achieve is a functionality where, regardless of whether NFC is tapped once or not, pressing a 'Refresh' button turns off NFC reading and then turns it back on when pressed again.

However, I encountered an error after implementing this.

Could you please let me know if there is anything unusual in my source code?

image

@divashuthron
Copy link
Author

const nfcTagLogin = async () => {
try {
NfcManager.start();
await NfcManager.requestTechnology(NfcTech.Ndef);
const tag = await NfcManager.getTag();
// console.log('NFC tagged, ID: ' + tag.id);

  webviewRef.current.postMessage(String(tag.id));
} catch (error) {
  console.error(error);
} finally {
  NfcManager.cancelTechnologyRequest().catch(() => 0);
}

};

const nfcClean = () => {
NfcManager.unregisterTagEvent();
NfcManager.cancelTechnologyRequest();
};

const nfcRefresh =() => {
nfcClean();
nfcTagLogin();
};

@georgipavlov-7DIGIT
Copy link

georgipavlov-7DIGIT commented Apr 25, 2024

I think the problem comes from trying to start the scanning immediatly after the cancellation. I had a similar problem and solved it by adding a small delay, which in your case will look like this

const nfcRefresh = () => {
  NfcManager.cancelTechnologyRequest().then(async () => {
    await new Promise((resolve) => setTimeout(resolve, 3500)).then(() => {
      nfcTagLogin()
    });
  })
}

There might be a better solution, but this it the one that i managed to come up with, hope it helps you. Note that I haven't tested that on android

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Jul 25, 2024
Copy link

github-actions bot commented Aug 9, 2024

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as completed Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants