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.
Create an account on the dashboard to generate a sandbox API key.
Check out the End User authentication section for how to generate short lived user JWTs
Find the Add Package Dependency menu item in Xcode, File > Swift Packages.
Then enter the Github repository for the package:
https://github.com/CardScan-ai/insurance-card-scan-ios
Import the package into your Xcode project files:
import InsuranceCardScan
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) {
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
should be passed a CardScanConfig
instance with properties for server connection, callback handling and UI customization.
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,
)
Checkout the full docs and iOS / Swift Widget docs.