cd Example
npm install
react-native run-android or react-native run-ios
-
Create a new React Native project:
react-native init NewProject
-
Add the local module to dependencies in package.json:
"dependencies": { "react": "16.0.0-alpha.6", "react-native": "0.43.3", "react-native-dbr":"file:../" },
-
Link dependencies:
react-native link
-
Use flatDir to define library path in android/build.gradle:
flatDir { dirs "$rootDir/../node_modules/react-native-dbr/android/lib" }
-
Use the module in index.android.js:
import BarcodeReaderManager from 'react-native-dbr'; BarcodeReaderManager.readBarcode('your license key', (msg) => { this.setState({result: msg}); }, (err) => { console.log(err); });
-
Create a new React Native project:
react-native init NewProject --version 0.44.3
-
Add the local module to dependencies in NewProject/package.json:
"dependencies": { "react": "16.0.0-alpha.6", "react-native": "0.43.3", "react-native-dbr":"file:../" }
-
Remove node_moudules and install:
sudo rm -rf node_moudules npm install or yarn
-
Add BarcodeReaderManager.xcodeproj to your project libraries :
-
Use the module in index.ios.js:
import BarcodeReaderManager from 'react-native-dbr'; BarcodeReaderManager.readBarcode('your license here').then((msg) =>{ this.setState({result: msg}); }).catch((err) => { console.log(err); });
-
In AppDelegate.m (In order to achieve navigation from react-native to viewController):
#import "../../../ios/BarcodeReaderManagerViewController.h" #import "../../../ios/DbrManager.h" - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // self.window.rootViewController = rootViewController; _nav = [[UINavigationController alloc] initWithRootViewController:_rootViewController]; self.window.rootViewController = _nav; _nav.navigationBarHidden = YES; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doNotification:) name:@"readBarcode" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backToJs:) name:@"backToJs" object:nil]; [self.window makeKeyAndVisible]; return YES; } -(void)doNotification:(NSNotification *)notification{ BarcodeReaderManagerViewController* dbrMangerController = [[BarcodeReaderManagerViewController alloc] init]; dbrMangerController.dbrManager = [[DbrManager alloc] initWithLicense:notification.userInfo[@"inputValue"]]; [self.nav pushViewController:dbrMangerController animated:YES]; } -(void)backToJs:(NSNotification *)notification{ [self.nav popToViewController:self.rootViewController animated:YES]; }
If you do not have a valid license, please contact [email protected]. With invalid license, the SDK can work but will not return a full result.