InsuranceCardScan(医保卡扫描)

我们的 InsuranceCardScan Swift 软件包让您能够轻松地将医保卡扫描和资格验证功能添加到任何 iOS 应用中,只需 5 分钟或更短时间。

沙盒 API 密钥

仪表板上创建一个帐户以生成沙盒 API 密钥。

查看最终用户身份验证部分,了解如何生成短期的用户 JWT。

快速开始

安装

在 Xcode 中找到“添加包依赖项”菜单项,位置:File(文件)> Swift Packages(Swift 包)。

然后输入包的 Github 存储库地址

https://github.com/CardScan-ai/insurance-card-scan-ios

使用

将软件包导入到您的 Xcode 项目文件中

import InsuranceCardScan

基本示例

使用生成的会话令牌创建 CardScannerViewController,将其呈现在当前视图控制器中,并注册回调函数来处理更新和错误。

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var cardScanButton: UIButton!

    @IBAction private func didTapScanCard(_ sender: UIButton) {
        startCardScanning()
    }

    private func startCardScanning() {
        // Replace <GENERATED_USER_TOKEN> with the user token generated from the server
        // See https://docs.cardscan.ai/authentication#end-user

        let userToken = "<GENERATED_USER_TOKEN>"
        
        let onSuccessCallback: (InsuranceCard) -> Void = { card in
            print("Card Scanned Successfully! - \(card)")
        }

        let onErrorCallback: (CardScanError) -> Void = { error in
            print("Card Scanning Error: \(error.localizedDescription)")
        }
        
        // Configure and present the CardScanViewController
        let config = CardScanConfig(sessionToken: userToken, live: false, onSuccess: onSuccessCallback, onError: onErrorCallback)
        let cardScanViewController = CardScanViewController()
        cardScanViewController.config = config
        
        // Present the CardScanViewController
        present(cardScanViewController, animated: true)
    }
}

可用属性

CardScanViewController 应该传递一个 CardScanConfig 实例,该实例包含用于服务器连接、回调处理和 UI 自定义的属性。

CardScanConfig(
  // Required
  sessionToken: token,
  live: false,
  onSuccess: onSuccess,

  // Recommended
  onCancel: onCancel,
  onError: onError,

  //eligibility
  eligibility: eligibility,
  onEligibilitySuccess: onEligibilitySuccess,
  onEligibilityError: onEligibilityError,

  // Optional
  backsideSupport: scanBackside,
  onRetry: onRetry,
  onProgress: onProgress,

  // Camera Options
  cameraOptions: cameraOptions,

  // UI Customization
  messages: messages,
  messageStyle: messagesStyle,
  autoSwitchActiveColor: autoSwitchActiveColor,
  autoSwitchInactiveColor: autoSwitchInactiveColor,
  progressBarColor: progressBarColor,
  widgetBackgroundColor: widgetBackgroundColor,
  logging: logging,
)

文档

查看完整文档 iOS / Swift Widget 文档