Skip to main content

Getting started | React Native Barcode Scanner

Installation#

The Scanbot Barcode SDK module is available as an npm package.

You can simply add it to your project by npm install:

npm install --save react-native-scanbot-barcode-scanner-sdk

Android Setup#

Scanbot Barcode Scanner SDK Maven Repositories

This React Native module depends on the native Scanbot Barcode Scanner SDK for Android. The Scanbot Barcode Scanner SDK for Android is distributed through our private Maven repositories. Please add these repositories in your android/build.gradle file in the section allprojects > repositories:

allprojects {    repositories {        mavenLocal()        maven {            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm            url "$rootDir/../node_modules/react-native/android"        }
        google()        jcenter()
        // Scanbot Barcode Scanner SDK Maven repositories:        maven { url 'https://nexus.scanbot.io/nexus/content/repositories/releases/' }        maven { url 'https://nexus.scanbot.io/nexus/content/repositories/snapshots/' }    }}

Enable Multidex

Make sure you have enabled multidex by setting multiDexEnabled to true in your android/app/build.gradle file:

android {  ...  defaultConfig {    ...    multiDexEnabled true  }}

Also add the following config in the same build.gradle file to avoid conflicts with the lib filename libc++_shared.so, which is used by React Native as well as by many other 3rd-party modules:

android {  ...  packagingOptions {      pickFirst '**/libc++_shared.so'  }}

iOS Setup#

Integration can be done only via CocoaPods.

In your ios/Podfile add the "RNScanbotSDK" pod:

pod 'RNScanbotBarcodeSDK', :podspec => '../node_modules/react-native-scanbot-barcode-scanner-sdk/react-native-scanbot-barcode-scanner-sdk.podspec'

The pod RNScanbotBarcodeSDK defines a dependency to the pod ScanbotBarcodeScannerSDK which is the native Scanbot Barcode SDK iOS Framework.

Run:

$ cd ios/$ pod install

That is it, no manual linking required anymore! Just open the Xcode workspace (.xcworkspace) and you should be able to build the native Scanbot Barcode SDK linked via CocoaPods.

Permissions#

In order to operate correctly an application that utilizes the ScanbotBarcodeScannerSDK module must have all required permissions to your App. Here is a listing of those permissions:

Android (must be added in your android/app/src/main/AndroidManifest.xml file)

  • <uses-permission android:name="android.permission.CAMERA" /> - This permission is used for the camera views.
  • <uses-feature android:name="android.hardware.camera" /> - Camera hardware features.

iOS (must be added in your Info.plist file)

  • NSCameraUsageDescription - "Privacy - Camera Usage Description". Describe why your app wants to access the device's camera.

API Reference#