Links

iOS 📱

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

Installation

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

Usage

Import the package into your Xcode project files:
import InsuranceCardScan

Scanning Button

A simple animated button that can quickly and easily be dropped into your application.
class ViewController: UIViewController {
​
var cardScanButton: CardScanButton!
override func viewDidLoad() {
super.viewDidLoad()
​
cardScanButton = CardScanButton(withIcon: true)
cardScanButton.addTarget(self, action: #selector(didTapScanCard), for: .touchUpInside)
self.view.addSubViews([cardScanButton])
//TODO: Add layout constraints for the button, or add using Interface Builder
}
​
Arguments
Type
Description
text
String
Button CTA. Default is "Scan Your Card"
withIcon
Boolean
Show or Hide camera icon. Default: False.
indicatorType
Enum
Choose from a few different UIActivity styles
textColor
UIColor
Color for the button CTA text. Default: White
bgColor
UIColor
Background color for button. Default: #007AFF
​

Basic Authentication:

Before loading the CardScannerViewController you must generate a session token from the CardScan API. See Authentication for more details.
private func didTapScanCard(_ sender: UIButton) {
///animate button on tap
button.showLoaderAboveImage(userInteraction:true)
​
var request = URLRequest(url: URL(string: "https://{{YOUR_SERVER_BASE_URL}}/cardscan-session")!)
request.httpMethod = "GET"
request.setValue("application/json", forHTTPHeaderField: "Accept")
URLSession.shared.dataTask(with: request) { [weak self] data, response, error in
///Extract session from server response
guard error == nil,
let data = data,
let json = try? JSONDecoder().decode([String: String].self, from: data),
let session = json["session"] else {
​
//handle errors calling server. :-(
print("Error calling server: ", error as Any)
return
}
///Trigger presentation of CardScannerView with user's session token.
DispatchQueue.main.async { [weak self] in
self?.presentCardScanner(sessionToken: session)
}
}.resume()
}

View Controller

Create the CardScannerViewController using the generated session token, present in the current view controller and register a callback to handle updates.
private func presentCardScanner(sessionToken: String) {
///Create CardScannerView with user session token
let cardScannerViewController = CardScannerViewController(sessionToken: sessionToken, live: true)
cardScannerViewController.present(from: self, animated:true) { [weak self] result in
switch result {
case .success(let card):
print(card)
//prepopulate UI and push results to server.
case .failure(let error):
//log and handle errors
print(error)
case .canceled:
print("User canceled -- update UI to refect this.")
@unknown default:
print("Unknown cardscan result")
}
}
}
Arguments
Type
Description
live
Boolean
Toggle the production or sandbox version. Default is False
sessionToken
String
A JWT token for the current user, see Authentication. Required.