MBBlinkIDUI 4.11.0.0

MBBlinkIDUI 4.11.0.0

由以下人员维护:Jure CularJura SkrlecJurica Cerovec



MBBlinkIDUI 4.11.0.0

  • 由:
  • MicroBlink

MicroBlink

BlinkID UI for iOS

BlinkID UI 是一个框架,允许您扫描任何受 BlinkID 支持的文档,甚至无需知道 Recognizer 是什么。

它包含可定制的扫描视图控制器和国家表格视图控制器。

查看我们的 演示应用

初识 BlinkID?请先查看 BlinkID SDK

目录

依赖

BlinkID UI 依赖于 BlinkID SDK。由于 BlinkID 使用 git-lfs,您需要安装它才能通过 Cocoapods 克隆/安装 BlinkID UI。安装 git-lfs 的最简单方法是通过 brew

brew install git-lfs
git lfs install

获取 BlinkID UI

  1. 安装git-lfs
  2. 克隆此仓库:https://github.com/BlinkID/blinkid-ui-ios.git 或将 pod 'MBBlinkIDUI' 添加到您的 podfile 中
  3. (不带 Cocoapods 的集成) 由于 BlinkID 作为子模块包含在内,您需要运行
git submodule init
git submodule update
  1. 查看示例或遵循 快速开始指南以在您的项目中使用它。

快速开始

BlinkID UI 是一个 Swift 框架,但我们也支持 Objective-C

CocoaPods 集成

MBBlinkIDUI 添加到您的 Podfile 中的目标内

pod 'MBBlinkIDUI'

运行

pod install

不带 Cocoapods 的集成

该框架依赖于 BlinkID SDK,因此您需要在 Xcode 项目的嵌入式框架中添加 BlinkID 框架。您可以通过从包含在此存储库中的 blinkid-ios 子模块拖动 Microblink.frameworkMicroblink.bundle 到您的项目中来实现此操作。

确保将 Microblink.framework 添加到您的目标中的嵌入式框架中,并将 Microblink.bundle 包含在 复制资源包资源 构建阶段中。

现在将 BlinkIDUI.xcodeproj 拖到您的项目探索器中。在项目导航器中,在 BlinkIDUI 项目中找到 Products,并将 BlinkIDUI.framework 拖到您目标中的嵌入式框架中。

实现

在将框架添加到您的项目后,您需要执行以下操作

  • 首先确保您正确地配置了 Microblink 许可证。有关更多信息,请参阅 BlinkID 文档
  • 实现 MBBlinkDelegate 协议。
  • 可选 使用 MBBlinkSettings 单例设置您想要的属性。
  • 可选 使用 MBTheme 中的扩展设置 UIColorUIFont 属性。
  • 创建一个 MBBlinkIDUI 实例
    • 请记住保留 MBBlinkIDUI 实例的引用。
    • 设置其 MBBlinkDelegate 属性。
    • 使用其 recognizerRunnerViewController 属性并 展示 它。

如果需要自定义扫描行为和 UI,请查看 常见问题解答。我们尽量使此框架易于定制,但仍然足够简单,可以开箱即用。

读取结果

MBRecognitionResult 类包含扫描结果,其中包含通常由文档中读取的姓氏和名字组合而成的 resultTitle

属性 resultEntries 包含一个 MBField 数组,这些是文档中读取的结果。在 MBField 中,您可以找到结果值和描述它的 MBFieldKey

可返回的图像有 frontSideDocumentImage(如果扫描的是双面或单面文档)和 backSideDocumentImage(如果扫描的是双面文档)。

如果使用的识别器支持人脸图像提取并且文档中包含人脸图像,则会返回 faceImage。同样的原则也适用于 signatureImage

最低速 Swift 示例

import UIKit
import BlinkIDUI
import MicroBlink

class ViewConroller: UIViewController {
    lazy var blinkIdUI: MBBlinkIDUI = MBBlinkIDUI()

     override func viewDidLoad() {
        super.viewDidLoad()
        MBMicroblinkSDK.sharedInstance().setLicenseKey("License-Key")
    }

    @IBAction func scan(_ sender: Any) {
        // You can set any settings for BlinkIDUI though MBBlinkSettings.sharedInstance:
        MBBlinkSettings.sharedInstance.frameGrabberMode = .nothing
        MBBlinkSettings.sharedInstance.shouldPlayScanSound = false

        blinkIdUI.delegate = self
        
        let recognizerRunnerViewController = blinkIdUI.recognizerRunnerViewController
        present(recognizerRunnerViewController, animated: true, completion: nil)
    }
}

extension ViewController: MBBlinkDelegate {
    
// Optional
    func didStartScanning(withState state: MBScanState) {
        // When scanning starts you will be notified through this method
    }
    
    func didScanEntireDocument(recognitionResult: MBRecognitionResult, successFrame: UIImage?) {
        blinkIdUI.pauseScanning()

        // Use recognition Result to present them to the user
        // After presenting you can finish the scanning by dismissing:
        // blinkIdUI.recognizerRunnerViewController.dismiss(animated: true, completion: nil)
        // or you can resumeScanning and restart it:

        blinkIdUI.resumeScanning()
        blinkIdUI.restartScanning()
    }
    
    func didScanFirstSide(recognitionResult: MBRecognitionResult, successFrame: UIImage?) {
        // If a document has two sides and if two separate recognizers are used 
        // this method will be called when the first side is scanned
    }
    
// Optional
    func didChangeDocument(newDocument: MBDocumentProvider, forCountry country: MBCountry) {
        // When a user changes the document you will be notified through this method
    }
    
// Optional
    func didTapCancelButton() {
        // You can set here what happens once the user taps the `X` button on the UI.
        blinkIdUI.recognizerRunnerViewController.dismiss(animated: true, completion: nil)
    }
}

最低速 Objective-C 示例

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@end

ViewController.m

#import "ViewController.h"
#import <MicroBlink/MicroBlink.h>
#import <BlinkIDUI/BlinkIDUI-Swift.h>

@interface ViewController ()<MBBlinkDelegate>

@property MBBlinkIDUI *blinkIDUI;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[MBMicroblinkSDK sharedInstance] setLicenseKey:@"License-Key"];
}

- (IBAction)scan:(id)sender {
    // You can set any settings for BlinkIDUI though MBBlinkSettings.sharedInstance:
    MBBlinkSettings.sharedInstance.frameGrabberMode = MBFrameGrabberModeNothing;
    MBBlinkSettings.sharedInstance.shouldPlayScanSound = NO;
    
    self.blinkIDUI = [[MBBlinkIDUI alloc] init];
    self.blinkIDUI.delegate = self;
    
    [self presentViewController:self.blinkIDUI.recognizerRunnerViewController animated:YES completion:nil];
}

// Optional
- (void)didChangeDocumentWithNewDocument:(MBDocumentProvider *)newDocument forCountry:(MBCountry *)country {
    // When a user changes the document you will be notified through this method
}

- (void)didScanEntireDocumentWithRecognitionResult:(MBRecognitionResult * _Nonnull)recognitionResult successFrame:(UIImage * _Nullable)successFrame {
    [self.blinkIDUI pauseScanning];
    // Use recognition Result to present them to the user
    // After presenting you can finish the scanning by dismissing:
    // [self.blinkIDUI.recognizerRunnerViewController dismissViewControllerAnimated:YES completion:nil];
    // or you can resumeScanning and restart it:
    
    
    [self.blinkIDUI resumeScanning];
    [self.blinkIDUI restartScanning];
}

- (void)didScanFirstSideWithRecognitionResult:(MBRecognitionResult * _Nonnull)recognitionResult successFrame:(UIImage * _Nullable)successFrame {
    // If a document has two sides and two separate recognizers are used
    // this method will be called when the first side is scanned
}

// Optional
- (void)didStartScanningWithState:(MBScanState)state {
    // You will be notified once the scanning starts through this method
}

// Optional
- (void)didTapCancelButton {
    [self.blinkIDUI.recognizerRunnerViewController dismissViewControllerAnimated:YES completion:nil];
}

@end

报告问题

如果您发现任何问题,请在GitHub上创建一个issue,但请尽可能提供详细信息。请指定:

  • 您是如何将框架添加到您的项目的,是使用Cocoapods还是手动编译。
  • Xcode版本。
  • 使用的是Swift还是Objective-C。
  • 运行所使用的iOS设备和iOS版本。
  • 我们可以用来复现问题的示例。您也可以通过help.microblink.com联系我们。

功能请求

如果您有任何功能请求,您可以创建一个issue,或者您可以实现它并提交一个pull请求。请注意,我们尽量保持API与框架的Android版本相似。

Pull请求

在提交pull请求时,请指定您的pull请求解决了哪个issue或添加了哪个功能。如果是功能,请添加一个示例说明为什么需要这个功能。否则,我们可能会拒绝您的pull请求。

FAQ

如何自定义颜色和字体?

查看MBTheme文件;它包含对UIColorUIFont的扩展。调色板分为3种颜色,主色、副色、三级色,还有一个从调色板分开的阴影色。UI上显示的每个文本都有其字体定义在这里,您可以设置字体属性并更改UI上的字体。

如何禁用扫描声音?

使用 MBBlinkSettings 共享实例,您可以设置各种扫描属性。要关闭成功扫描后的声音,请将 shouldPlayScanSound 设置为 false

如何限制选择特定国家和文档类型?

使用以下 MBDocumentChooserSettings

  • 使用 countryFilter 过滤用户是否要在国家表格视图控制器中选择的国家。
  • 使用 shouldShowDocumentTypeTabs 显示/隐藏选择文档的控制器。
  • 使用 shouldShowCountryChooser 显示/隐藏打开国家表格视图控制器的按钮。
  • 使用 sectionIndexMinimumDisplayRowCount 设置在国家表格视图控制器中显示索引侧面的最小行数。
  • 使用 isDocument(document: MBDocumentType, supportedForCountry country: MBCountry) -> Bool 来显示/隐藏来自特定国家的文档。例如,如果您不希望用户扫描/选择 克罗地亚身份证,则在 country 实例的 countryCodeMBSupportedCountry.croatia 且文档是 MBDocumentType.identityCard 时,此方法将返回 false
  • 使用 defaultDocumentTypeForCountry(country: MBCountry) -> MBDocumentType 为给定的国家设置要扫描的第一个文档类型。
  • 使用 didTapChooseCountry(documentChooserViewController: MBDocumentChooserViewController) 设置用户点击选择国家按钮时发生的事情。

如何只扫描文档的一侧?

MBBlinkSettings 共享实例中设置 shouldScanBothDocumentSidesfalse,这样扫描双面文档的任何一侧都将返回结果。

如何隐藏手电筒按钮?

MBBlinkSettings 共享实例中将 shouldShowTorchButton 设置为 false

如何隐藏 X 按钮?

MBBlinkSettings 共享实例中将 shouldShowCancelButton 设置为 false

如何修改或删除 Scanner Difficulty 警告?

实现自己的 MBTimeoutHandler 并在 MBBlinkSettings 共享实例中设置属性 timeoutHandler

如何修改文档验证?

您可以通过将 MBBlinkSettings 中的 shouldValidateDocuments 设置为 false 来关闭文档验证。如果将 shouldValidateDocuments 设置为 true,可以通过实现 MBInvalidDocumentHandler 并在 MBBlinkSettings 共享实例中设置 invalidDocumentHandler 来更改未验证文档的默认行为。实现您自己的 MBTimeoutHandler 并在 MBBlinkSettings 共享实例中设置属性 timeoutHandler

如何获取成功帧?

MBBlinkSettings 中设置 frameGrabberMode成功所有帧。如果您想接收所有帧,您需要通过在 MBBlinkSettings 共享实例中设置 frameGrabberDelegate 属性来提供 MBFrameGrabberDelegate

如何为标签和按钮设置自己的文本?

MBBlinkSettings 共享实例中,您可以找到 MBBlinkLanguageSettings 属性。您可以通过默认使用框架提供的 .strings 文件中的文本来设置各种文本属性。

我在哪里获得项目的许可证?

在我们网站上注册,您可以从开发者仪表板获取一个BlinkID演示许可证密钥。

故障排除

出现以下错误

ignoring file .../PPBlinkID/MicroBlink.framework/MicroBlink, file was built for unsupported file format ( 0x76 0x65 0x72 0x73 0x69 0x6F 0x6E 0x20 0x68 0x74 0x74 0x70 0x73 0x3A 0x2F 0x2F ) which is not the architecture being linked (x86_64)MicroBlink.framework/MicroBlink

此问题最可能的原因是缺少git-lfs,或克隆仓库后安装它。简单地安装git-lfs,遵循指示并运行git-lfs pull

如果您使用Cocoapods安装了框架,请运行

pod cache clean
pod install

您需要清理Cocoapods缓存,因为它在未安装git-lfs的情况下克隆了仓库。