iOS 📱

Our InsuranceCardScan swift package makes it easy to add health insurance card scanning and eligibility verification to any iOS application in 5 minutes or less.


Find the Add Package Dependency menu item in Xcode, File > Swift Packages.

Then enter the Github repository for the package:


Import the package into your Xcode project files:

import InsuranceCardScan

Basic Example:

Create the CardScannerViewController using the generated session token, present in the current view controller and register a callbacks to handle updates and errors.

import UIKit

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

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

    private func startCardScanning() {
        // Replace <GENERATED_USER_TOKEN> with the user token generated from the server
        // See

        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)

Available Properties

CardScanViewController should be passed a CardScanConfig instance with properties for server connection, callback handling and UI customization.

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

  // Recommended
  onCancel: onCancel,
  onError: onError,

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

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

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

Main Properties

UI/UX Customization Properties

The iOS widget is designed to be customizable. Please see the #customization section of UI Components to adjust these elements to match your application's branding and theme:

Customization ⚙️

Note: All UI/UX Props are optional


onSuccess Callback

The onSuccess callback is triggered when the card scanning process completes successfully. This function receives the scanned card data as an argument.


Define a function that receives the scanned card data and pass it to the CardScanConfig.

let handleCardScanSuccess: (InsuranceCard) -> Void = { card in
    print("Card scanned successfully: \(card)")

let config = CardScanConfig(
    sessionToken: "<GENERATED_USER_TOKEN>",
    onSuccess: handleCardScanSuccess

let cardScanViewController = CardScanViewController(config: config)
present(cardScanViewController, animated: true)

onError Callback

The onError callback is executed when there is a failure during the card scanning process. This function receives an error object as an argument.


Define a function that receives an error object and pass it to the CardScanConfig.

let handleCardScanError: (CardScanError) -> Void = { error in
    print("Scanning failed: \(error.localizedDescription)")

let config = CardScanConfig(
    sessionToken: "<GENERATED_USER_TOKEN>",
    onError: handleCardScanError

In this example, the handleCardScanError function logs the error object to the console when a scanning failure occurs.

By using the onSuccess and onError props, you can handle successful and failed scanning events, allowing you to implement custom actions or display appropriate messages to the user.

You can find examples of the#error-screens at the bottom of this document

Possible errors returned to the onError callback.

struct CardScanError: Error {
    let message: String
    let type: String
    let code: Int

onCancel Callback

The onCancel callback enables you to execute a custom function when the user cancels the card scanning process. This can be useful for tracking user behavior, navigating to a different part of the application, or displaying an appropriate message.


Pass a function to the CardScanConfig that will be executed when the user cancels the scanning process.

let handleCancel: () -> Void = {
    print("Scanning cancelled by the user.")

let config = CardScanConfig(
    sessionToken: "<GENERATED_USER_TOKEN>",
    onCancel: handleCancel

onRetry Callback

The onRetry callback allows you to execute a custom function when a retry is triggered due to a scanning failure.


Pass a function to the CardScanConfig that will be executed upon retry.

let handleRetry: () -> Void = {
    print("Retry triggered.")

let config = CardScanConfig(
    sessionToken: "<GENERATED_USER_TOKEN>",
    onRetry: handleRetry

In this example, the handleRetry function logs the retry event to the console when a retry is triggered.

onProgress Callback

The onProgress callback allows you to execute a custom function to report progress during the scanning process.


let handleProgress: (ScanProgress) -> Void = { progress in
    print("Card ID: \(progress.cardId) - Scan Count: \(progress.scanCount) - Card State: \(progress.cardState)")

let config = CardScanConfig(
    sessionToken: "<GENERATED_USER_TOKEN>",
    onProgress: handleProgress

In this example, the handleProgress callback logs the progress during a live scanning operation. When backsideSupport is enabled the scan counter will reset to zero when the card is flipped to scan the back side.

For the majority of live scanning scenarios, the scanning will be completed within 2-3 scans. In situations with low light or occluded card elements, the scan count can go as high as 12.

Additional Features

Eligibility Verification

Eligibility Verification is crucial in healthcare for confirming a patient's insurance coverage and benefits before services are provided, streamlining billing and enhancing patient care.

By providing subscriber and provider details through our React component, users can initiate the verification process effortlessly. The widget offers real-time feedback with success and error callbacks, simplifying integration into your application's UI.

See Eligibility Verification 🩻 for more details.

Last updated