Skip to content

Commit

Permalink
Merge pull request #172 from BlinkID/release/v6.13.0
Browse files Browse the repository at this point in the history
Release/v6.13.0
  • Loading branch information
mparadina authored Jan 3, 2025
2 parents 1571c67 + 64824ff commit 3dfef67
Show file tree
Hide file tree
Showing 15 changed files with 299 additions and 15 deletions.
2 changes: 1 addition & 1 deletion BlinkID/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blinkid-cordova",
"version": "6.12.0",
"version": "6.13.0",
"description": "A small and powerful ID card scanning library",
"cordova": {
"id": "blinkid-cordova",
Expand Down
2 changes: 1 addition & 1 deletion BlinkID/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="blinkid-cordova"
version="6.12.0">
version="6.13.0">

<name>BlinkIdScanner</name>
<description>A small and powerful ID card scanning library</description>
Expand Down
2 changes: 1 addition & 1 deletion BlinkID/scripts/initIOSFramework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
HERE="$(dirname "$(test -L "$0" && readlink "$0" || echo "$0")")"
pushd "${HERE}/../src/ios/" > /dev/null

LINK='https://github.com/BlinkID/blinkid-ios/releases/download/v6.12.0/BlinkID.xcframework.zip'
LINK='https://github.com/BlinkID/blinkid-ios/releases/download/v6.13.0/BlinkID.xcframework.zip'
FILENAME='BlinkID.xcframework.zip'

# BlinkID framework will be obtained via wget or curl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
import com.microblink.blinkid.entities.recognizers.blinkid.generic.CustomClassRules;
import com.microblink.blinkid.entities.recognizers.blinkid.generic.DetailedFieldType;
import com.microblink.blinkid.entities.recognizers.blinkid.generic.DependentInfo;

import com.microblink.blinkid.entities.recognizers.blinkid.generic.ClassFilter;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.Parcel;
import androidx.annotation.NonNull;

public abstract class BlinkIDSerializationUtils {
public static JSONObject serializeMrzResult(MrzResult mrzResult) throws JSONException {
Expand Down Expand Up @@ -444,6 +446,70 @@ public static CustomClassRules[] deserializeCustomClassRules(JSONArray jsonArray
}
}

public static ClassFilter deserializeClassFilter(JSONObject jsonClassFilter) {
return new ClassFilter() {
@Override
public boolean classFilter(@NonNull ClassInfo classInfo) {
JSONArray jsonIncludeClasses = jsonClassFilter.optJSONArray("includeClasses");
JSONArray jsonExcludeClasses = jsonClassFilter.optJSONArray("excludeClasses");
boolean includeClass = false;
boolean excludeClass = true;

if (jsonIncludeClasses != null) {
if (jsonIncludeClasses.length() > 0) {
for (int x = 0; x < jsonIncludeClasses.length(); x++) {
try {
includeClass = includeClass || matchClassInfo(classInfo, jsonIncludeClasses.getJSONObject(x));
} catch (JSONException e) {}
}
} else {
includeClass = true;
}
} else {
includeClass = true;
}

if (jsonExcludeClasses != null) {
for (int x = 0; x < jsonExcludeClasses.length(); x++) {
try {
excludeClass = excludeClass && !matchClassInfo(classInfo, jsonExcludeClasses.getJSONObject(x));
} catch (JSONException e) {}
}
}

return includeClass && excludeClass;
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(@NonNull Parcel parcel, int i) {
}
};
}

// helper methods for ClassFilter
private static boolean matchClassInfo(ClassInfo classInfo, JSONObject jsonObject) {
Country country = getEnumValue(jsonObject, "country", Country.class);
Type type = getEnumValue(jsonObject, "type", Type.class);
Region region = getEnumValue(jsonObject, "region", Region.class);

return (country == null || classInfo.getCountry() == country) &&
(type == null || classInfo.getType() == type) &&
(region == null || classInfo.getRegion() == region);
}

private static <T extends Enum<T>> T getEnumValue(JSONObject jsonObject, String key, Class<T> enumType) {
try {
return enumType.getEnumConstants()[jsonObject.getInt(key)];
} catch (JSONException | IndexOutOfBoundsException e) {
return null;
}
}

public static JSONArray serializeDependentInfo (DependentInfo[] dependentInfos) throws JSONException {
JSONArray jsonDependentInfos = new JSONArray();
for (int i = 0; i < dependentInfos.length; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public Recognizer<?> createRecognizer(JSONObject jsonObject) {
recognizer.setAllowUnverifiedMrzResults(jsonObject.optBoolean("allowUnverifiedMrzResults", true));
recognizer.setAnonymizationMode(com.microblink.blinkid.entities.recognizers.blinkid.generic.AnonymizationMode.values()[jsonObject.optInt("anonymizationMode", 3)]);
recognizer.setBlurStrictnessLevel(com.microblink.blinkid.entities.recognizers.blinkid.generic.imageanalysis.StrictnessLevel.values()[jsonObject.optInt("blurStrictnessLevel", 1)]);
recognizer.setClassFilter(BlinkIDSerializationUtils.deserializeClassFilter(jsonObject.optJSONObject("classFilter")));
recognizer.setCombineFrameResults(jsonObject.optBoolean("combineFrameResults", true));
recognizer.setCustomClassRules(BlinkIDSerializationUtils.deserializeCustomClassRules(jsonObject.optJSONArray("customClassRules")));
recognizer.setEnableBlurFilter(jsonObject.optBoolean("enableBlurFilter", true));
Expand Down Expand Up @@ -113,6 +114,7 @@ public JSONObject serializeResult(Recognizer<?> recognizer) {
jsonResult.put("signatureImage", SerializationUtils.encodeImageBase64(result.getSignatureImage()));
jsonResult.put("specificDocumentValidity", BlinkIDSerializationUtils.serializeStringResult(result.getSpecificDocumentValidity()));
jsonResult.put("sponsor", BlinkIDSerializationUtils.serializeStringResult(result.getSponsor()));
jsonResult.put("vehicleOwner", BlinkIDSerializationUtils.serializeStringResult(result.getVehicleOwner()));
jsonResult.put("vehicleType", BlinkIDSerializationUtils.serializeStringResult(result.getVehicleType()));
jsonResult.put("visaType", BlinkIDSerializationUtils.serializeStringResult(result.getVisaType()));
} catch (JSONException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public Recognizer<?> createRecognizer(JSONObject jsonObject) {
recognizer.setAllowUnverifiedMrzResults(jsonObject.optBoolean("allowUnverifiedMrzResults", true));
recognizer.setAnonymizationMode(com.microblink.blinkid.entities.recognizers.blinkid.generic.AnonymizationMode.values()[jsonObject.optInt("anonymizationMode", 3)]);
recognizer.setBlurStrictnessLevel(com.microblink.blinkid.entities.recognizers.blinkid.generic.imageanalysis.StrictnessLevel.values()[jsonObject.optInt("blurStrictnessLevel", 1)]);
recognizer.setClassFilter(BlinkIDSerializationUtils.deserializeClassFilter(jsonObject.optJSONObject("classFilter")));
recognizer.setCombineFrameResults(jsonObject.optBoolean("combineFrameResults", true));
recognizer.setCustomClassRules(BlinkIDSerializationUtils.deserializeCustomClassRules(jsonObject.optJSONArray("customClassRules")));
recognizer.setEnableBlurFilter(jsonObject.optBoolean("enableBlurFilter", true));
Expand Down Expand Up @@ -99,6 +100,7 @@ public JSONObject serializeResult(Recognizer<?> recognizer) {
jsonResult.put("signatureImage", SerializationUtils.encodeImageBase64(result.getSignatureImage()));
jsonResult.put("specificDocumentValidity", BlinkIDSerializationUtils.serializeStringResult(result.getSpecificDocumentValidity()));
jsonResult.put("sponsor", BlinkIDSerializationUtils.serializeStringResult(result.getSponsor()));
jsonResult.put("vehicleOwner", BlinkIDSerializationUtils.serializeStringResult(result.getVehicleOwner()));
jsonResult.put("vehicleType", BlinkIDSerializationUtils.serializeStringResult(result.getVehicleType()));
jsonResult.put("visaType", BlinkIDSerializationUtils.serializeStringResult(result.getVisaType()));
jsonResult.put("vizResult", BlinkIDSerializationUtils.serializeVizResult(result.getVizResult()));
Expand Down
2 changes: 1 addition & 1 deletion BlinkID/src/android/libBlinkID.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repositories {
}

dependencies {
implementation('com.microblink:blinkid:6.12.0@aar') {
implementation('com.microblink:blinkid:6.13.0@aar') {
transitive = true
}
}
Expand Down
42 changes: 36 additions & 6 deletions BlinkID/src/ios/sources/CDVBlinkIDScanner.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
#import "MBOverlaySettingsSerializers.h"
#import "MBRecognizerWrapper.h"
#import "MBSerializationUtils.h"
#import "MBBlinkIDSerializationUtils.h"

#import <BlinkID/BlinkID.h>

@interface CDVPlugin () <MBOverlayViewControllerDelegate, MBScanningRecognizerRunnerDelegate, MBFirstSideFinishedRecognizerRunnerDelegate>
@interface CDVPlugin () <MBOverlayViewControllerDelegate, MBScanningRecognizerRunnerDelegate, MBFirstSideFinishedRecognizerRunnerDelegate, MBBlinkIdMultiSideRecognizerDelegate, MBBlinkIdSingleSideRecognizerDelegate>

@property (nonatomic, retain) CDVInvokedUrlCommand *lastCommand;

Expand All @@ -38,6 +38,8 @@ @interface CDVBlinkIDScanner ()
@property (nonatomic, strong) MBRecognizerCollection *recognizerCollection;
@property (nonatomic) id<MBRecognizerRunnerViewController> scanningViewController;
@property (nonatomic, strong) MBRecognizerRunner *recognizerRunner;
@property (nonatomic, strong) MBOverlayViewController *overlayVc;
@property (nonatomic, strong) NSDictionary *jsonRecognizerCollection;

@property (class, nonatomic, readonly) NSString *RESULT_LIST;
@property (class, nonatomic, readonly) NSString *CANCELLED;
Expand Down Expand Up @@ -75,18 +77,27 @@ - (void)scanWithCamera:(CDVInvokedUrlCommand *)command {
[self setLastCommand:command];

NSDictionary *jsonOverlaySettings = [self sanitizeDictionary:[self.lastCommand argumentAtIndex:0]];
NSDictionary *jsonRecognizerCollection = [self sanitizeDictionary:[self.lastCommand argumentAtIndex:1]];
_jsonRecognizerCollection = [self sanitizeDictionary:[self.lastCommand argumentAtIndex:1]];
NSDictionary *jsonLicenses = [self sanitizeDictionary:[self.lastCommand argumentAtIndex:2]];

if([self setLicense:jsonLicenses]) {
[self setLanguage:(NSString *)jsonOverlaySettings[@"language"] country:(NSString *)jsonOverlaySettings[@"country"]];

self.recognizerCollection = [[MBRecognizerSerializers sharedInstance] deserializeRecognizerCollection:jsonRecognizerCollection];
self.recognizerCollection = [[MBRecognizerSerializers sharedInstance] deserializeRecognizerCollection:_jsonRecognizerCollection];

// create overlay VC
MBOverlayViewController *overlayVC = [[MBOverlaySettingsSerializers sharedInstance] createOverlayViewController:jsonOverlaySettings recognizerCollection:self.recognizerCollection delegate:self];
_overlayVc = [[MBOverlaySettingsSerializers sharedInstance] createOverlayViewController:jsonOverlaySettings recognizerCollection:self.recognizerCollection delegate:self];
for (MBRecognizer *recognizer in self.recognizerCollection.recognizerList) {
if([recognizer isKindOfClass:[MBBlinkIdMultiSideRecognizer class]]) {
[(MBBlinkIdMultiSideRecognizer *)recognizer setDelegate:self];
break;
} else if ([recognizer isKindOfClass:[MBBlinkIdSingleSideRecognizer class]]) {
[(MBBlinkIdSingleSideRecognizer *)recognizer setDelegate:self];
break;
}
}

UIViewController<MBRecognizerRunnerViewController>* recognizerRunnerViewController = [MBViewControllerFactory recognizerRunnerViewControllerWithOverlayViewController:overlayVC];
UIViewController<MBRecognizerRunnerViewController>* recognizerRunnerViewController = [MBViewControllerFactory recognizerRunnerViewControllerWithOverlayViewController:_overlayVc];
[recognizerRunnerViewController setModalPresentationStyle:UIModalPresentationFullScreen];

self.scanningViewController = recognizerRunnerViewController;
Expand Down Expand Up @@ -245,6 +256,25 @@ - (void)overlayDidTapClose:(MBOverlayViewController *)overlayViewController {
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:resultDict];
[self.commandDelegate sendPluginResult:result callbackId:self.lastCommand.callbackId];
}
- (BOOL)multiSideClassInfoFilter:(nullable MBClassInfo *)classInfo {
return [MBBlinkIDSerializationUtils deserializeClassFilter:_jsonRecognizerCollection classInfo:classInfo];
}

- (void)onMultiSideDocumentSupportStatus:(BOOL)isDocumentSupported {
if([_overlayVc isKindOfClass:[MBBlinkIdOverlayViewController class]]) {
[(MBBlinkIdOverlayViewController *)_overlayVc onDocumentSupportStatus:isDocumentSupported];
}
}

- (BOOL)classInfoFilter:(MBClassInfo *)classInfo {
return [MBBlinkIDSerializationUtils deserializeClassFilter:_jsonRecognizerCollection classInfo:classInfo];
}

- (void)onDocumentSupportStatus:(BOOL)isDocumentSupported {
if([_overlayVc isKindOfClass:[MBBlinkIdOverlayViewController class]]) {
[(MBBlinkIdOverlayViewController *)_overlayVc onDocumentSupportStatus:isDocumentSupported];
}
} //TODO SSAD SERZITION UTILS

+ (NSString *)RESULT_LIST {
return @"resultList";
Expand Down
1 change: 1 addition & 0 deletions BlinkID/src/ios/sources/MBBlinkIDSerializationUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
+(NSDictionary * _Nonnull) serializeNSDate:(NSDate * _Nullable) value;
+(MBCustomClassRules * _Nonnull) deserializeMBCustomClassRules:(NSDictionary * _Nullable)jsonCustomClassRules;
+(NSMutableArray<NSDictionary *> * _Nullable) serializeDependentInfo:(NSArray<MBDependentInfo *>* _Nullable)dependentInfos;
+ (BOOL)deserializeClassFilter:(NSDictionary * _Nullable)jsonRecognizerCollection classInfo:(MBClassInfo * _Nullable)classInfo;
@end
56 changes: 56 additions & 0 deletions BlinkID/src/ios/sources/MBBlinkIDSerializationUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,59 @@ +(NSDictionary *) serializeClassInfo:(MBClassInfo *)classInfo {
};
}

+ (BOOL)deserializeClassFilter:(NSDictionary *)jsonRecognizerCollection classInfo:(MBClassInfo *)classInfo {
BOOL includeClass = NO;
BOOL excludeClass = YES;
NSDictionary *classFilter;

for (NSDictionary *recognizer in jsonRecognizerCollection[@"recognizerArray"]) {
NSString *recognizerType = recognizer[@"recognizerType"];

if ([recognizerType isEqualToString:@"BlinkIdMultiSideRecognizer"] ||
[recognizerType isEqualToString:@"BlinkIdSingleSideRecognizer"]) {

classFilter = recognizer[@"classFilter"];
if (!classFilter) {
return YES;
}
}
}

NSArray *addClassToClassFilter = classFilter[@"includeClasses"];
if (addClassToClassFilter != nil && ![addClassToClassFilter isEqual:[NSNull null]]) {
if ([addClassToClassFilter count] > 0) {
for (int i = 0; i < [addClassToClassFilter count]; i++) {
NSDictionary *jsonClassInfo = addClassToClassFilter[i];
includeClass = includeClass || [self matchClassFilter:jsonClassInfo classInfo:classInfo];
}
} else {
includeClass = YES;
}
} else {
includeClass = YES;
}

NSArray *removeClassFromClassFilter = classFilter[@"excludeClasses"];
if (removeClassFromClassFilter != nil && ![removeClassFromClassFilter isEqual:[NSNull null]]) {
for (int i = 0; i < [removeClassFromClassFilter count]; i++) {
NSDictionary *jsonClassInfo = removeClassFromClassFilter[i];
excludeClass = excludeClass && ![self matchClassFilter:jsonClassInfo classInfo:classInfo];
}
}
return includeClass && excludeClass;
}

+ (BOOL)matchClassFilter:(NSDictionary *)jsonClassFilterInfo classInfo:(MBClassInfo *)classInfo {

NSNumber *country = [jsonClassFilterInfo valueForKey:@"country"];
NSNumber *region = [jsonClassFilterInfo valueForKey:@"region"];
NSNumber *type = [jsonClassFilterInfo valueForKey:@"type"];

return (![self isNotNullandNil:country] || classInfo.country == country.integerValue) &&
(![self isNotNullandNil:type] || classInfo.type == type.integerValue) &&
(![self isNotNullandNil:region]|| classInfo.region == region.integerValue);
}

+(NSDictionary *) serializeVizResult:(MBVizResult *)vizResult {
return @{
@"firstName" : [MBBlinkIDSerializationUtils serializeMBStringResult:vizResult.firstName],
Expand Down Expand Up @@ -407,5 +460,8 @@ +(NSNumber *)serializeMBSide:(MBSide) value {

return jsonDependentInfos;
}
+ (BOOL)isNotNullandNil:(NSNumber *)value {
return ![value isEqual:[NSNull null]] && (value != nil);
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ -(NSDictionary *) serializeResult {
[jsonResult setValue:[MBSerializationUtils encodeMBImage:self.result.signatureImage] forKey:@"signatureImage"];
[jsonResult setValue:[MBBlinkIDSerializationUtils serializeMBStringResult:self.result.specificDocumentValidity] forKey:@"specificDocumentValidity"];
[jsonResult setValue:[MBBlinkIDSerializationUtils serializeMBStringResult:self.result.sponsor] forKey:@"sponsor"];
[jsonResult setValue:[MBBlinkIDSerializationUtils serializeMBStringResult:self.result.vehicleOwner] forKey:@"vehicleOwner"];
[jsonResult setValue:[MBBlinkIDSerializationUtils serializeMBStringResult:self.result.vehicleType] forKey:@"vehicleType"];
[jsonResult setValue:[MBBlinkIDSerializationUtils serializeMBStringResult:self.result.visaType] forKey:@"visaType"];
[jsonResult setValue:[MBBlinkIDSerializationUtils serializeDependentInfo:self.result.dependentInfos] forKey:@"dependentsInfo"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ -(NSDictionary *) serializeResult {
[jsonResult setValue:[MBSerializationUtils encodeMBImage:self.result.signatureImage] forKey:@"signatureImage"];
[jsonResult setValue:[MBBlinkIDSerializationUtils serializeMBStringResult:self.result.specificDocumentValidity] forKey:@"specificDocumentValidity"];
[jsonResult setValue:[MBBlinkIDSerializationUtils serializeMBStringResult:self.result.sponsor] forKey:@"sponsor"];
[jsonResult setValue:[MBBlinkIDSerializationUtils serializeMBStringResult:self.result.vehicleOwner] forKey:@"vehicleOwner"];
[jsonResult setValue:[MBBlinkIDSerializationUtils serializeMBStringResult:self.result.vehicleType] forKey:@"vehicleType"];
[jsonResult setValue:[MBBlinkIDSerializationUtils serializeMBStringResult:self.result.visaType] forKey:@"visaType"];
[jsonResult setValue:[MBBlinkIDSerializationUtils serializeVizResult:self.result.vizResult] forKey:@"vizResult"];
Expand Down
Loading

0 comments on commit 3dfef67

Please sign in to comment.