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

How to read multiple Mifare cards (not NDEF) on iOS? #713

Open
dcanora opened this issue Apr 9, 2024 · 1 comment
Open

How to read multiple Mifare cards (not NDEF) on iOS? #713

dcanora opened this issue Apr 9, 2024 · 1 comment

Comments

@dcanora
Copy link

dcanora commented Apr 9, 2024

Hello! I asked a version of this question last June but got no response. Asking again to see if anyone has found a solution...

I need to allow the user to read multiple NFC cards, with the app processing the tag value and providing quick "thumbs up/down" feedback to the user between each read. I have no problem doing this on Android but can't seem to get it working on iOS.

On iOS single read is easy enough to implement. But to read multiple cards, the user has to wait or actively dismiss the iOS UI and then press the Start Scanning button again in my app. This is a bit of a kludge and slows them down, so I'd like to find a way to avoid it.

Is there a way in iOS to successfully loop in code to read multiple cards?

Details...

On Android I call .requestTechnology(), .getTag(), .mifareUltralightHandlerAndroid.mifareUltralightReadPages() and .cancelTechnologyRequest(). I then process the value returned, give the user feedback and then repeat the process to read the next card, until canceled by the user.

This doesn't work on iOS. I've separated the calls to .requestTechnology(NfcTech.MifareIOS) and .cancelTechnologyRequest() so they only get called before the first call and when canceled, respectively. I'm trying to use readNfc(), below, to do each nfc read. The first tag reads fine, but when the app calls readNfc() a second time - even though no tag is near the phone - the app behaves like the first tag is still present - .getTag() always immediately returns the first card's data (as shown in a console.log of nfcTag.id) and the call to .sendMifareCommandIOS() always fails, presumably because there is actually no tag to read. No matter what I do, it seems the first card read is somehow still "seen" by .getTag() the second time readNfc() is called.

 const readNfc = async () => {
    let readPages = null;
    console.log("[nfcServices] readNfc Starting...");
    
      try {
          // Wait for tag    
          await NfcManager.setAlertMessageIOS('Scan a card…’);
          const nfcTag = await NfcManager.getTag();
          console.log('[nfcServices] readNfc getTag returned ', nfcTag.id);
          
          // Read one four-page array from tag
          readPages = await NfcManager.sendMifareCommandIOS([0x30, 16]);
          await NfcManager.setAlertMessageIOS(‘Card read!');
          console.log('[nfcServices] readNfc readPages: ', readPages);
      
      } catch (ex) {
          // Error
          console.log('[nfcServices] readNfc ERROR: ', ex);
          NfcManager.cancelTechnologyRequest().catch(() => 0);
      } finally {
          console.log('[nfcServices] readNfc returning: ', readPages);
          return(readPages);
      }
  }
@dcanora
Copy link
Author

dcanora commented May 2, 2024

If not a solution, can anyone confirm my experience that scanning cards using .sendMifareCommandIOS on IOS is "single shot" and requires dismissing the iOS NFC UI between each read? Thanks!

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