Parse document class info
documentClassInfo identifies the document that was scanned.
Its country, region, and documentType fields each carry two values:
id: a strongly-typed identifier, taken from the enum the SDK was built withrawValue: the same classification as a plain string
Branch on id wherever you can, and reach for rawValue only when id is absent.
The examples below assume result is the scanning result.
Read the ID fields
id is an enum, so the compiler catches typos and your editor can autocomplete the values.
Prefer it for all comparisons.
- Web (TS)
- Android (Kotlin)
- iOS (Swift)
const classInfo = result.documentClassInfo;
console.log("Country:", classInfo?.country?.id); // "croatia"
console.log("Region:", classInfo?.region?.id); // "california", or absent
console.log("Document type:", classInfo?.documentType?.id); // "id"
if (classInfo?.country?.id === "croatia" && classInfo?.documentType?.id === "id") {
// Croatian identity card
}
val classInfo = result.documentClassInfo
println("Country: ${classInfo?.country?.id}") // CountryId.Croatia
println("Region: ${classInfo?.region?.id}") // RegionId.California, or null
println("Document type: ${classInfo?.documentType?.id}") // DocumentTypeId.Id
if (classInfo?.country?.id == CountryId.Croatia && classInfo.documentType?.id == DocumentTypeId.Id) {
// Croatian identity card
}
Note that iOS uses countryId, regionId, and documentTypeId, not just id.
let classInfo = result.documentClassInfo
print("Country:", String(describing: classInfo.country?.countryId)) // .croatia
print("Region:", String(describing: classInfo.region?.regionId)) // .california, or nil
print("Document type:", String(describing: classInfo.documentType?.documentTypeId)) // .id
if classInfo.country?.countryId == .croatia, classInfo.documentType?.documentTypeId == .id {
// Croatian identity card
}
Fall back to the raw value
BlinkID receives support for new document classes over the air (OTA), after the SDK was built.
When a document matches one of those classes, the enum has no matching value, so id is absent while rawValue is still populated.
Check id first, and compare rawValue only if id is absent.
This keeps the enum path in place for every document the SDK already knows, and lets you ship support for a new class as a string comparison instead of an SDK upgrade.
- Web (TS)
- Android (Kotlin)
- iOS (Swift)
const documentType = result.documentClassInfo?.documentType;
if (documentType?.id) {
handleKnownDocumentType(documentType.id);
} else if (documentType?.rawValue === "NEW VALUE AVAILABLE ONLY OTA") {
handleSpecialCase();
}
val documentType = result.documentClassInfo?.documentType
val documentTypeId = documentType?.id
if (documentTypeId != null) {
handleKnownDocumentType(documentTypeId)
} else if (documentType?.rawValue == "NEW VALUE AVAILABLE ONLY OTA") {
handleSpecialCase()
}
let documentType = result.documentClassInfo.documentType
if let documentTypeId = documentType?.documentTypeId {
handleKnownDocumentType(documentTypeId)
} else if documentType?.rawValue == "NEW VALUE AVAILABLE ONLY OTA" {
handleSpecialCase()
}
Write the fallback so an unrecognized rawValue is handled, not ignored.
A class delivered over the air can reach your app before you have written any code for it.
Find the raw values
See Supported documents for the browsable catalog.
Raw values are listed in the supported documents JSON, per document and per platform:
https://docs.microblink.com/blinkid/supported-docs/{version}/supported-documents.json
Each entry has an sdk object with a web, android, and ios key, and each of those holds the id and rawValue for country, region, and documentType.
For example:
"sdk": {
"web": {
"country": { "id": "japan", "rawValue": "JAPAN" },
"region": null,
"documentType": { "id": null, "rawValue": "SPECIFIED RESIDENCE CARD" }
}
}
Absent values
Two kinds of absence mean different things:
- The whole component (
country,region, ordocumentType) is absent: the document has no such classification. Most documents are not regional, soregionis commonly absent. - The component is present but its
idis absent: the class exists, was delivered over the air, and is only available asrawValue.
When the document could not be classified at all, documentClassInfo is either fully absent (web, Android) or niled (iOS).