Restrict scanning to specific document types or countries
In BlinkID v8000, you restrict which documents are accepted at scan time with a document class filter. The filter is a predicate that runs for each detected document. If it allows the document, scanning proceeds; if it rejects the document, the document's data is not returned, and the scan surfaces it as a filtered or unsupported document.
This filter is the v8000 replacement for the old up-front document-rule allowlists. Instead of declaring allowed documents in configuration, you decide per detected document whether to accept it.
The filter receives a documentClassInfo describing the detected document.
Each platform exposes the same fields, with the naming and enum conventions of that platform.
Add a document class filter
The following filter allows only Croatian and German documents. Any other document is rejected.
- Web (TS)
- Android (Kotlin)
- iOS (Swift)
- Flutter (Dart)
- React Native (TS)
On web, register a predicate with addDocumentClassFilter on the blinkId object returned by createBlinkId.
Returning true allows the document; returning false rejects it, and the document is marked as unsupported-document.
const blinkId = await createBlinkId({ licenseKey: "your-license-key" });
const cleanup = blinkId.addDocumentClassFilter((documentClassInfo) => {
return documentClassInfo.country === "croatia" || documentClassInfo.country === "germany";
});
addDocumentClassFilter returns a cleanup function.
Call it when you no longer want the filter to apply.
On Android, implement the ClassFilter interface and pass an instance through BlinkIdUxSettings.
ClassFilter is Parcelable, so annotate your implementation with @Parcelize.
Return true to allow the document, false to filter it out.
import com.microblink.blinkid.core.result.classinfo.Country
import com.microblink.blinkid.core.result.classinfo.DocumentClassInfo
import com.microblink.blinkid.ux.settings.ClassFilter
import kotlinx.parcelize.Parcelize
@Parcelize
class CountryClassFilter : ClassFilter {
override fun classAllowed(documentClass: DocumentClassInfo): Boolean {
return documentClass.country == Country.Croatia ||
documentClass.country == Country.Germany
}
}
BlinkIdCameraScanningScreen(
blinkIdSdk = blinkIdSdk,
uxSettings = BlinkIdUxSettings(classFilter = CountryClassFilter()),
onScanningSuccess = { result ->
// use result
},
onScanningCanceled = { }
)
On iOS, implement the BlinkIDClassFilter protocol and pass an instance to BlinkIDAnalyzer.
Return true to allow the document, false to filter it out.
class CountryClassFilter: BlinkIDClassFilter {
func classAllowed(classInfo: BlinkIDSDK.DocumentClassInfo) -> Bool {
classInfo.country == .croatia || classInfo.country == .germany
}
}
let analyzer = try await BlinkIDAnalyzer(
sdk: sdk,
classFilter: CountryClassFilter()
)
On Flutter, build a ClassFilter with an includeDocuments list of DocumentFilter entries and pass it to performScan.
Only documents matching an entry are allowed; everything else is rejected.
final classFilter = ClassFilter()
..includeDocuments = [
DocumentFilter(country: Country.croatia),
DocumentFilter(country: Country.germany),
];
final result = await blinkIdPlugin.performScan(
blinkIdSdkSettings: sdkSettings,
blinkIdSessionSettings: sessionSettings,
classFilter: classFilter,
);
On React Native, build a classFilter with an includeDocuments array and pass it to performScan.
Only documents matching an entry are allowed; everything else is rejected.
const classFilter = {
includeDocuments: [
{ country: Country.Croatia },
{ country: Country.Germany },
],
};
const result = await performScan({ sdkSettings, sessionSettings, classFilter });