This is a fork of jackbayliss/react-native-nfc-card-reader repo with the CardNfcUtils integrated to the repo to avoid issues in Android 12. The issue in case was something related to Target S+ compatibilities that was happening on class: com.pro100svitlo.creditCardNfcReader.utils.CardNfcUtils
This package is specifically designed to scan credit/debit cards using an Android devices NFC reader and return the card number, expiry and card type.
This package will only work on Android and isn't available for iOS as of 2020 because Apple do not allow 3rd party iPhone apps to use the Core NFC framework.
$ npm install react-native-nfc-card-reader --save
npm install "https://github.com/jackbayliss/react-native-nfc-card-reader.git#gradle7.0" --save
$ react-native link react-native-nfc-card-reader
import NfcCardReader from 'react-native-nfc-card-reader';
NfcCardReader.startNfc(function(cardDetails){
// Card details contain the callback data below, see the options.
that.setState({cardNumber : cardDetails.cardNumber})
that.setState({expiryDate : cardDetails.expiryDate})
that.setState({cardType : cardDetails.cardType})
})
Ensure you add the following to your AndroidManifest.xml
located in android\app\src\main
<activity android:name="com.jackbayliss.nfcreader.NfcCardReaderActivity"/>
startNfc(callback)
-> Will start the NFC Activity and expects a callback function that will return the card details it's scanned.
cardType
-> Provides the type of the card scanned.
cardNumber
-> Provides the full card number scanned.
expiryDate
-> Providers the expiry date of the card scanned.
firstName
-> Card owners first name.
lastName
-> Card owners last name.
You can find the sample app here
I am by no means an Android developer, but saw this as a huge thing no one had produced for React Native. So, if you can expand or improve on my basic implementation feel free to create a pull request.
MIT - expanded from here
A special thanks to pro100svitlo for their library which gave me the ability to create this module. A special thanks to decoder10 for fixing a few issues, and adding firstname / lastname - as well as allowing any NFC cards to be scanned.