revtel / react-native-nfc-manager

React Native NFC module for Android & iOS
MIT License
1.32k stars 312 forks source link

Implement restartTechnologyRequestIOS #703

Closed icedevml closed 4 months ago

icedevml commented 4 months ago

In some cases we might get disconnected from the NFC tag. When that happens, we are not able to communicate with the NFC tag anymore, so on iOS the only valid further step is to invalidate NFC session with an error, and ask the user to try again. It also seems to be impossible to process multiple NFC tags within a single CoreNFC tag reading session (unless I'm mistaken).

This PR implements additional method called restartTechnologyRequestIOS which essentialy wires the NFCTagReaderSession.restartPolling() into the react-native-nfc-manager. This API makes it possible to process multiple tags or to retry an NFC operation against the same tag in case of any failure, without actually restarting the NFC scanning prompt.

whitedogg13 commented 4 months ago

@icedevml it's awesome, thanks for the contribution!

TomClarkson commented 1 week ago

Could you please give an example of how to use restartTechnologyRequestIOS?

icedevml commented 1 week ago

Whenever you have the transceive failure, you can call something like await NfcManager.setAlertMessageIOS("Failed to read the tag, please tap it again...") in order to tell the user what is going on, then you can immediately call await NfcManager.restartTechnologyRequestIOS(). The latter call will block until a new tag is detected, at which point you can use it normally with NfcManager.transceive(...).