Ionic
The Ionic plugin has been completely reworked in release 8.4, resulting in changes to the public interfaces. This section provides a side-by-side comparison of the basic features between releases 8.3 and 8.4
Plugin Installation
The plugin's name has been changed. The previous plugin version is deprecated and will be supported for one more release (8.5), so it's strongly recommended to migrate to the new plugin version.
ionic cordova plugin add @regulaforensics/document-reader
ionic cordova plugin add @regulaforensics/document-reader-core-fullauthrfid
npm install --save @regulaforensics/ionic-native-document-reader
ionic cordova plugin add @regulaforensics/cordova-plugin-document-reader-api
ionic cordova plugin add @regulaforensics/cordova-plugin-document-reader-core-fullauthrfid
Accessing DocumentReader
DocumentReader.instance.
var documentReader = DocumentReader.instance
documentReader.
DocumentReader.
Preparing Database
await documentReader.prepareDatabase("Full", showProgress)
onDatabasePrepared()
DocumentReader.prepareDatabase("Full").then((message) => {
if (message != "database prepared")
console.log("Downloading database: " + message + "%")
else {
console.log("DB prepared")
onDatabasePrepared()
}
})
Initialization
var [success, error] = await documentReader.initialize(new InitConfig(license))
if (success) console.log("Init complete")
else console.log(error.code + ": " + error.message)
var config = new DocReaderConfig()
config.license = license
config.delayedNNLoad = true
DocumentReader.initializeReader(config).then((message) => {
result = JSON.parse(message)
if (!result.success) {
console.log("Init error: " + result.error.message)
} else {
console.log("Init complete")
}
})
Accessing Fields
var tag = documentReader.tag
documentReader.tag = "new tag"
DocumentReader.getTag().then((value) => {
console.log("Tag: " + value)
})
DocumentReader.setTag(value).then((m) => {
console.log("Tag set: " + value)
})
Accessing Available Scenarios
var scenarios = documentReader.availableScenarios
DocumentReader.getAvailableScenarios().then((scenariosString) => {
var scenariosJson = JSON.parse(scenariosString)
var scenarios = []
for (var index in scenariosJson) {
var scenarioJson = scenariosJson[index]
var scenario = DocumentReaderScenario.fromJson(typeof scenarioJson === "string" ? JSON.parse(scenarioJson) : scenarioJson)
scenarios.add(scenario)
}
})
Changing Configuration
documentReader.functionality.showCaptureButton = true
var functionality = new Functionality()
functionality.showCaptureButton = true
DocumentReader.setFunctionality(functionality)
Scanning Document
documentReader.startScanner(
ScannerConfig.withScenario(Scenario.MRZ),
handleCompletion,
)
var config = new ScannerConfig()
config.scenario = Enum.ScenarioIdentifier.SCENARIO_MRZ
DocumentReader.startScanner(config).then((m) => {
handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(m)))
})
Reading RFID
documentReader.rfid(new RFIDConfig(handleCompletion))
DocumentReader.startRFIDReader(false, false, false).then((m) => {
var id = "rfidOnProgressCompletion"
if (raw.substring(0, id.length) === id) {
raw = raw.substring(id.length, raw.length)
var notification = DocumentReaderNotification.fromJson(JSON.parse(raw))
} else
handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(raw)))
})