CardScan React Native installation guide
Visit our website at https://cardscan.io for examples. Native libraries for android and iOS are also available in github.
CardScan is open source, and available under a free-to-try license. See the license section for details.
Install and setup permission cardscan-ios
No additional steps are necessary to install cardscan-android.
2. Install the react-native-cardscan package from NPM
$ npm install react-native-cardscan
$ react-native link react-native-cardscan
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-cardscan
and addRNCardscan.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNCardscan.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project
Cmd+R
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:implementation project(':react-native-cardscan')
- Append the following lines to
android/settings.gradle
:include ':react-native-cardscan' project(':react-native-cardscan').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cardscan/android')
- Open
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.getbouncer.RNCardscanPackage;
to the imports at the top of the file - Add
new RNCardscanPackage()
to the list returned by thegetPackages()
method
- Add
Install and setup permission for CardScan iOS with directions here
Also, the instructions to configure your API key in Obj-C is here
The podfile in your ~/ios/Podfile
in your project should look similar to:
platform :ios, '10.0'
target 'Your App' do
...
pod 'CardScan'
pod 'react-native-cardscan', :path => '../node_modules/react-native-cardscan/react-native-cardscan.podspec'
end
To configure your API key, open up android/app/src/main/java/[...]/MainApplication.java
and add the following
import com.getbouncer.RNCardscanModule;
...
...
public void onCreate() {
...
RNCardscanModule.apiKey = "<YOUR_API_KEY_HERE>";
RNCardscanModule.enableEnterCardManually = false; // set to true to enable entering a card manually
RNCardscanModule.enableExpiryExtraction = false; // set to true for experimental expiry extraction
RNCardscanModule.enableNameExtraction = false; // set to true for experimental name extraction
}
Check device support
import Cardscan from 'react-native-cardscan';
Cardscan.isSupportedAsync()
.then(supported => {
if (supported) {
// YES, show scan button
} else {
// NO
}
})
Scan card
import Cardscan from 'react-native-cardscan';
Cardscan.scan()
.then(({action, payload, canceled_reason}) => {
if (action === 'scanned') {
const { number, expiryMonth, expiryYear, issuer, legalName } = payload;
// Display information
} else if (action === 'canceled') {
if (canceled_reason === 'enter_card_manually') {
// the user elected to enter a card manually
} else if (canceled_reason === 'camera_error') {
// there was an error with the camera
} else if (canceled_reason === 'fatal_error') {
// there was an error during the scan
} else if (canceled_reason === 'user_canceled') {
// the user canceled the scan
} else {
// the scan was canceled for an unknown reason
}
} else if (action === 'skipped') {
// User skipped
} else if (action === 'unknown') {
// Unknown reason for scan canceled
}
})
Inside example
, you can find an example React Native project that you can run.
To run the example app, do the following:
- Navigate to
example
npm install
- Update API key in
android/app/src/main/java/com/example/MainApplication.java
for Android andios/example/AppDelegate.m
for iOS. - Point the android app to the SDK: create a file
example/android/local.properties
with a linesdk.dir=<full_path_to_android_sdk>
- To run Android app:
react-native run-android
- To run iOS app:
react-native run-ios
- A workaround with XCode 11 is to add a bridge header https://stackoverflow.com/a/56176956
- A workaround with a newer XCode build system is to switch to the legacy build https://stackoverflow.com/a/51089264
- react-native was unable to start the app after installing it. To start it manually, run the following command:
adb reverse tcp:8081 tcp:8081 && adb shell am start -n com.example/com.example.MainActivity
Adam Wushensky, Sam King, Zain ul Abi Din, and Stefano Suryanto
This library is available under paid and free licenses. See the LICENSE file for the full license text.
In short, this library will remain free forever for non-commercial applications, but use by commercial applications is limited to 90 days, after which time a licensing agreement is required. We're also adding some legal liability protections.
After this period commercial applications need to convert to a licensing agreement to continue to use this library.
- Details of licensing (pricing, etc) are available at https://cardscan.io/pricing, or you can contact us at license@getbouncer.com.
What's allowed under the license:
- Free use for any app for 90 days (for demos, evaluations, hackathons, etc).
- Contributions (contributors must agree to the Contributor License Agreement)
- Any modifications as needed to work in your app
What's not allowed under the license:
- Commercial applications using the license for longer than 90 days without a license agreement.
- Using us now in a commercial app today? No worries! Just email license@getbouncer.com and we’ll get you set up.
- Redistribution under a different license
- Removing attribution
- Modifying logos
- Indemnification: using this free software is ‘at your own risk’, so you can’t sue Bouncer Technologies, Inc. for problems caused by this library
Questions? Concerns? Please email us at license@getbouncer.com or ask us on slack.