FPhiSelphIDWidgetiOS 1.25.1

FPhiSelphIDWidgetiOS 1.25.1

Mario Sevilla Montoya, 开发者, Cristian Bou, amartinez, Jose Antonio Juan Prado 维护。



 
依赖项
GoogleMLKit/TextRecognition= 6.0.0
GoogleMLKit/TextRecognitionKorean= 6.0.0
GoogleMLKit/TextRecognitionJapanese= 6.0.0
FPhiMBWidgetiOS= 5.20.0
zipzap>= 0
 

  • Facephi

galeria-selphid-logo

Selphid widget for iOS

带有市场上最好的实时 OCR 以及人脸活性的安全数字入职解决方案。

selphid

目录

需求

SelphID 处件以 XCFramerwork 格式分发,附带一个以 Zip 文件分发的资源包。该框架可以在 iOS 10.0 或更高版本上部署。

快速开始指南

将 SelphID 小部件集成到您项目中最快的方式是使用 CocoaPods。

为了使用 Cocoapods,您需要在项目目录中创建一个 podfile 文件。

$ touch podfile

将以下内容添加到您的 podfile 文件中:

platform :ios, '10.0'
target 'Your-App-Target' do
  pod 'FPhiSelphIDWidgetiOS'
end

在您的项目中安装小部件及其依赖项

$ pod install

打开新生成的 Xcode 工作空间 (.xcworkspace)。

编程实现

要实现在项目中使用 SelphID 小部件,请遵循以下步骤。

  1. 引用头文件。

Swift

import FPhiSelphIDWidgetiOS

Objective-C

#import <FPhiSelphIDWidgetiOS/FPhiSelphIDWidgetiOS.h>
  1. 调用 SelphID 小部件。

SelphID 小部件必须通过 Viewcontroller 来调用。以下代码片段展示了如何实现一个调用 SelphID 小部件的方法。

请注意,SelphID 小部件需要有效的许可证才能正确运行,否则将抛出错误。

Swift

func showDocumentWidget() {
        // Get path of resource
        
        guard let resource = Bundle.main.path(forResource: "fphi-selphid-widget-resources-selphid-1.0", ofType: "zip") else { return }

        // Get path of license
        guard let path = Bundle.main.path(forResource: "license", ofType: "lic") else { return }
        guard let license = try? String(contentsOfFile: path, encoding: .utf8) else { return }

       
        do {
           try selphIDWidget = FPhiSelphIDWidget(frontCameraIfAvailable: true, resources: resource, delegate: self, license: license)
        } catch {
           //Catch possible invokation error here
        }
        
        // Checking the correct creation of the widget
        guard let widget = selphIDWidget else { return }

        widget.scanMode = .SMSearch

        // If you want to get a front and back image at the same time
        widget.wizardMode = true

        // Show capture image before snap
        widget.showAfterCapture = true

        // If you want to obtain the data in a more accurate way enter the locale in the specificData property
        widget.specificData = documentModel

        widget.scanType = .DTIDCard

        // Start widget extraction
        widget.startExtraction()

        // Show widget
        present(widget, animated: true)
    }

对于数据提取,SelphID 小部件代理,FPhiSelphIDWidgetProtocol,必须遵守。

extension ViewController: FPhiSelphIDWidgetProtocol {
  /*
   This event is launched when the document capture is complete

   Returns the possible types of results extracted from the OCR extraction.

   Note: Not is recommended to take this data out of the terminal without encryption.

   Capture format
   - Standard: Cropped image from points of interest, to avoid the presence of visual noise. Ideal to show the user. Ex: frontDocument
   - Raw: Original image. Ideal to send to the server and to deal with it. Ex: rawFrontDocument

   Security
   - Plain: They are raw data without applying any encryption layer. It is ideal to show the user. Ex: frontDocument
   - Token: Apply an encryption layer to the data sent. Which is possible to decrypt from the SDK on the server. Ex: tokenFrontDocument

   Side
   - Front: Document front image. Ex: frontDocument
   - Back: Document back image. Ex: backDocument
   - Face: Document facial image. Ex: faceImage
   */

  func captureFinished() {
      // Retrieve data captured from widget
      guard let results = selphIDWidget?.results else { return }

      // Retrieve frontal document image captured from widget
      if let front = results.frontDocument {
          print(front)
      }

      // Retrieve back document image captured from widget
      if let back = results.backDocument {
          print(back)
      }

      // Retrieve face document image captured from widget
      if let face = results.faceImage {
          
          print(face)
      }

      /*
       Returns the possible types of results extracted from the OCR extraction.

       - ocrResults: Returns an unencrypted key value dictionary. Suitable to show in case of flow that contemplates it.
       - tokenOCR: Returns an encrypted key value dictionary. Suitable to send to the server and decrypt it there.
       */
      if let data = results.ocrResults as? [String: String] {
          /*
           This serves to update the list that shows the extracted data.
           It has nothing to do with the logic of the widget, it is only demonstrative.
           */
         print(data)
      }
  }

  // This event is launched when the time to recognize a document has been exceeded
  func captureTimeout() {

  }

  // This event is launched when the user has canceled the capture of the document from the widget interface
  func captureCancelled() {

  }

  // This event is launched when the widget has suffered an error during capture
  func captureFailed(_ error: Error!) {

  }
}

Objective-C

-(void)showDocumentWidget {
  NSLog(@"Widget - Capture Document Front");

   NSString *license = [self readLicense:LICENSE_PATH];

   NSError *error = nil;
   NSBundle *bundle = [NSBundle bundleForClass:[FrontViewController class]];
   _selphidWidget = [[FPhiSelphIDWidget alloc] initWithFrontCameraIfAvailable:true
                                                                    resources:[bundle pathForResource:RESOURCES_PATH ofType:@"zip"]
                                                                     delegate:self
                                                                      license:license
                                                                        error:&error];

   if (error != nil) {
       switch (error.code) {
           case FWMEUnknown:
               NSLog(@"Widget - construction error. Unknown error");
               break;
           case FWMECameraPermission:
               NSLog(@"Widget - construction error. Camera permission denied");
               break;
       }
       return;
   }

   _selphidWidget.scanSide = DSFront;
   _selphidWidget.scanMode = SMSearch;

   // If you want to obtain the data in a more accurate way enter the locale in the specificData property
   NSString *locale = @"ES";
   _selphidWidget.specificData = [NSString stringWithFormat:@"%@|<ALL>", locale];

   // If you want to get a front and back image at the same time
   _selphidWidget.wizardMode = false;

   _selphidWidget.showAfterCapture = true;

   if (_selphidWidget.wizardMode) self.previousData = nil;
   _selphidWidget.tokenPreviousCaptureData = self.previousData;

   [_selphidWidget StartExtraction];

   [self presentViewController:_selphidWidget animated:true completion:nil];
}

对于数据提取,SelphID 小部件代理,FPhiSelphIDWidgetProtocol,必须遵守。

#pragma Widget delegate
/**
Invoked when the extraction process is finished.
- Mandatory method
*/
- (void)CaptureFinished {
   NSLog(@"Widget - Extraction finished");

   if (_selphidWidget.wizardMode)
       self.previousData = nil;
   else
       self.previousData = _selphidWidget.results.tokenOCR;

   _frontImageView.image = _selphidWidget.results.frontDocument;
   _nextButton.enabled = true;
}

/**
Invoked when the extraction process fail.
- Optional method
*/
- (void)CaptureFailed:(NSError *)error {
   NSLog(@"Widget - Extraction failed");
}

/**
Invoked when extraction process is aborted by timeout.
- Optional method
*/
- (void)CaptureTimeout {
   NSLog(@"Widget - Extraction timeout");
}

/**
Invoked when extraction process is cancelled by user.
- Optional method
*/
- (void)CaptureCancelled {
   NSLog(@"Widget - Extraction cancelled");
}