Skip to content

Commit

Permalink
7.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins committed Feb 22, 2024
1 parent 5048a96 commit 1b054ca
Show file tree
Hide file tree
Showing 50 changed files with 11,308 additions and 9,206 deletions.
52 changes: 10 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,19 @@
# Regula Document Reader (React Native)
# Regula Document Reader SDK for React Native

Regula Document Reader SDK allows you to read various kinds of identification documents, passports, driving licenses, ID cards, etc. All processing is performed completely _**offline**_ on your device. No any data leaving your device.

You can use native camera to scan the documents or image from gallery for extract all data from it.

This repository contains the source code of the Document Reader API, and the sample application that demonstrates the _**API**_ calls you can use to interact with the Document Reader library.

# Contents
* [How to build demo application](#how-to-build-demo-application)
* [Troubleshooting license issues](#troubleshooting-license-issues)
* [Documentation](#documentation)
* [Additional information](#additional-information)

## How to build demo application
1. Visit [client.regulaforensics.com](https://client.regulaforensics.com) to get a trial license (`regula.license` file). The license creation wizard will guide you through the necessary steps.
2. Download or clone this repository using the command `git clone https://github.com/regulaforensics/react-native-document-reader.git`.
3. Run the following commands in Terminal:
```bash
$ cd example
$ npm install
$ cd ios
$ pod install
```

**Note**: make sure that Metro Bundler is running when you run your app. Otherwise, run `npx react-native start` command. If it fails to start, run `git init` from Project root, then `npx react-native start`.

4. Android:
* Copy the `regula.license` file to the `example/android/app/src/main/assets` folder.
* Run `npx react-native run-android` inside `example` folder - this is just one way to run the app. You can also run it directly from within Android Studio. **Note**: `npx react-native log-android` is used to view logs.

**Note**: if the running failed with the following error `Error: spawn ./gradlew EACCES`, try to run the following command `chmod +x gradlew` within the `example/android` directory.

5. iOS:
* Copy the `regula.license` file to the `example/ios/DocumentReader` folder.
* Run `npx react-native run-ios` inside `example` folder - this is just one way to run the app. You can also run it directly from within Xcode.

### Troubleshooting license issues
If you have issues with license verification when running the application, please verify that next is true:
1. The OS, which you use, is specified in the license (e.g., Android and/or iOS).
3. The license is valid (not expired).
4. The date and time on the device, where you run the application, are valid.
5. You use the latest release version of the Document Reader SDK.
6. You placed the `license` into the correct folder as described [here](#how-to-build-demo-application).

## Documentation
You can find documentation on API [here](https://docs.regulaforensics.com/develop/doc-reader-sdk/mobile/react-native).

## Additional information
If you have any technical questions, feel free to [contact](mailto:[email protected]) us or create issue [here](https://github.com/regulaforensics/react-native-document-reader/issues).
You can find documentation [here](https://docs.regulaforensics.com/develop/doc-reader-sdk/mobile/react-native).

## License

To obtaining the production license or other purchasing information, please [submit an inquiry](https://regulaforensics.com/talk-to-an-expert) and our sales team will contact you shortly.

## Support

To use our SDK in your own app you need to [purchase](https://pipedrivewebforms.com/form/394a3706041290a04fbd0d18e7d7810f1841159) a commercial license.
Please do not hesitate to [contact us](https://support.regulaforensics.com/hc/requests/new), if you need any assistance or want to report a bug / suggest an improvement.
2 changes: 1 addition & 1 deletion RNDocumentReaderApi.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ Pod::Spec.new do |s|
s.source = { :http => 'file:' + __dir__ }
s.ios.deployment_target = '11.0'
s.source_files = "ios/*.{h,m}"
s.dependency 'DocumentReader', '6.9.3102'
s.dependency 'DocumentReader', '7.1.3379'
s.dependency 'React'
end
20 changes: 10 additions & 10 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
buildscript {
ext {
kotlinVersion = '1.8.22'
gradleVersion = '8.0.2'
}

repositories {
google()
mavenCentral()
}

dependencies {
classpath "com.android.tools.build:gradle:${project.ext.gradleVersion}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${project.ext.kotlinVersion}"
classpath "com.android.tools.build:gradle:8.1.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22"
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 33
// Conditional for compatibility with AGP <4.2.
if (project.android.hasProperty("namespace")) {
namespace 'com.regula.documentreader'
}

compileSdk 34

defaultConfig {
minSdkVersion 21
targetSdkVersion 33
targetSdk 34
versionCode 1
versionName "1.0"
}
Expand All @@ -41,7 +41,7 @@ dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+'
//noinspection GradleDependency
implementation('com.regula.documentreader:api:6.9.9406') {
implementation('com.regula.documentreader:api:7.1.9667') {
transitive = true
}
}
Expand Down
152 changes: 78 additions & 74 deletions android/src/main/java/com/regula/documentreader/BluetoothUtil.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
//
// BluetoothUtil.kt
// DocumentReader
//
// Created by Pavel Masiuk on 21.09.2023.
// Copyright © 2023 Regula. All rights reserved.
//

package com.regula.documentreader

import android.Manifest.permission.*
Expand All @@ -21,88 +29,84 @@ import com.regula.documentreader.api.internal.permission.BluetoothPermissionHelp
import com.regula.documentreader.api.internal.permission.BluetoothSettingsHelper.isBluetoothEnabled
import com.regula.documentreader.api.internal.permission.BluetoothSettingsHelper.isLocationServiceEnabled

class BluetoothUtil {
companion object {
private const val REQUEST_ENABLE_LOCATION = 196
private const val REQUEST_ENABLE_BT = 197
const val REQUEST_ENABLE_LOCATION = 196
const val REQUEST_ENABLE_BT = 197

@SuppressLint("StaticFieldLeak")
var bleManager: BLEWrapper? = null
@SuppressLint("StaticFieldLeak")
var bleManager: BLEWrapper? = null

@RequiresPermission("android.permission.BLUETOOTH_CONNECT")
private fun requestEnableBle(activity: Activity) {
val enableIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
activity.startActivityForResult(enableIntent, REQUEST_ENABLE_BT)
}
@RequiresPermission("android.permission.BLUETOOTH_CONNECT")
fun requestEnableBle(activity: Activity) {
val enableIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
activity.startActivityForResult(enableIntent, REQUEST_ENABLE_BT)
}

private fun requestEnableLocationService(activity: Activity) {
val myIntent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
activity.startActivityForResult(myIntent, REQUEST_ENABLE_LOCATION)
}
fun requestEnableLocationService(activity: Activity) {
val myIntent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
activity.startActivityForResult(myIntent, REQUEST_ENABLE_LOCATION)
}

// requestEnableBle() is called after a check for permission
@SuppressLint("MissingPermission")
fun isBlePermissionsGranted(activity: Activity): Boolean {
if (!isLocationServiceEnabled(activity)) {
requestEnableLocationService(activity)
return false
}
deniedBluetoothPermissions(activity)?.let {
requestPermissions(activity, it, BLE_ACCESS_PERMISSION)
return false
}
if (!isBluetoothEnabled(activity)) {
requestEnableBle(activity)
return false
}
return true
}
// requestEnableBle() is called after a check for permission
@SuppressLint("MissingPermission")
fun isBlePermissionsGranted(activity: Activity): Boolean {
if (!isLocationServiceEnabled(activity)) {
requestEnableLocationService(activity)
return false
}
deniedBluetoothPermissions(activity)?.let {
requestPermissions(activity, it, BLE_ACCESS_PERMISSION)
return false
}
if (!isBluetoothEnabled(activity)) {
requestEnableBle(activity)
return false
}
return true
}

private fun deniedBluetoothPermissions(activity: Activity): Array<String>? {
val result = mutableListOf<String>()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
result.addAll(deniedBluetoothPermission(activity, BLUETOOTH_SCAN))
result.addAll(deniedBluetoothPermission(activity, BLUETOOTH_CONNECT))
} else
result.addAll(deniedBluetoothPermission(activity, ACCESS_FINE_LOCATION))
return result.let { if (it.size > 0) it.toTypedArray() else null }
}
fun deniedBluetoothPermissions(activity: Activity): Array<String>? {
val result = mutableListOf<String>()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
result.addAll(deniedBluetoothPermission(activity, BLUETOOTH_SCAN))
result.addAll(deniedBluetoothPermission(activity, BLUETOOTH_CONNECT))
} else
result.addAll(deniedBluetoothPermission(activity, ACCESS_FINE_LOCATION))
return result.let { if (it.size > 0) it.toTypedArray() else null }
}

private fun deniedBluetoothPermission(
activity: Activity,
permission: String
): Array<String> {
if (checkSelfPermission(activity, permission) != PERMISSION_GRANTED)
return arrayOf(permission)
return arrayOf()
}
fun deniedBluetoothPermission(
activity: Activity,
permission: String
): Array<String> {
if (checkSelfPermission(activity, permission) != PERMISSION_GRANTED)
return arrayOf(permission)
return arrayOf()
}

fun startBluetoothService(
activity: Activity,
onConnected: (Boolean) -> Unit,
onDisconnected: () -> Unit,
onReady: () -> Unit
) {
val bleIntent = Intent(activity, RegulaBleService::class.java)
activity.startService(bleIntent)
fun startBluetoothService(
activity: Activity,
onConnected: (Boolean) -> Unit,
onDisconnected: () -> Unit,
onReady: () -> Unit
) {
val bleIntent = Intent(activity, RegulaBleService::class.java)
activity.startService(bleIntent)

activity.bindService(bleIntent, object : ServiceConnection {
override fun onServiceConnected(name: ComponentName, service: IBinder) {
bleManager = (service as RegulaBleService.LocalBinder).service.bleManager
val isBleManagerConnected = bleManager?.isConnected == true
onConnected(isBleManagerConnected)
if (!isBleManagerConnected) {
bleManager?.addCallback(object : BleWrapperCallback() {
override fun onDeviceReady() {
bleManager!!.removeCallback(this)
onReady()
}
})
activity.bindService(bleIntent, object : ServiceConnection {
override fun onServiceConnected(name: ComponentName, service: IBinder) {
bleManager = (service as RegulaBleService.LocalBinder).service.bleManager
val isBleManagerConnected = bleManager?.isConnected == true
onConnected(isBleManagerConnected)
if (!isBleManagerConnected) {
bleManager?.addCallback(object : BleWrapperCallback() {
override fun onDeviceReady() {
bleManager!!.removeCallback(this)
onReady()
}
}

override fun onServiceDisconnected(name: ComponentName) = onDisconnected()
}, 0)
})
}
}
}

override fun onServiceDisconnected(name: ComponentName) = onDisconnected()
}, 0)
}
Loading

0 comments on commit 1b054ca

Please sign in to comment.