iOS
Integration in a 100% native iOS app requires setting up a separate ViewController that contains the WebView where the verification module will show up.
This guide will walk you through setting up the WebView app and making sure your app has a direct connection to the iOS SDK Flow and can receive events and data from it.
For more detailed information about GetID options and in-depth descriptions of methods, please see the developer site.
1. Create and host an empty HTML page for loading the verification module
You should create a separate HTML page with your integration code. This page should be hosted on your servers, for example on: https://test.[PARTNER].com/native-test.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Test</title>
</head>
<body>
<script src="https://[PARTNER].regily.com/[KEY].js"></script>
<script>
window.onCheckinLoad = (sdk) => {
window.checkin.settings.setLang('en')
window.checkin.settings.setCustomData({
OCRFlow: "[FLOW]",
})
window.checkin.settings.setVariant('idscan')
// Listen to module events to be able to close the webview activity when user closes the Signup module
window.checkin.events.setOnAny((eventData) => {
if (window.webkit.messageHandlers.onEvent) {
window.webkit.messageHandlers.onEvent.postMessage(eventData)
}
})
sdk.signUp.open()
}
</script>
</body>
</html>
Once the user has scanned all documents, the data is returned with the completed event which can be used to retrieve and verify data from the flow.
If you want or need you can capture this data in the setOnComplete
event and the results can be found in the data.ocrData
property.
Here's an example of how to capture and read the data from the setOnComplete
.
window.onCheckinLoad = (checkin) => {
// The configuration settings from step 1
checkin.settings.setLang('en')
checkin.dataFlow.setKnownData(`{"user": { "firstName": "John", "lastName": "Doe" }}`)
checkin.dataFlow.setOnComplete(({ data, completeData }) => {
// Process and send the data to your back-end here
console.log('Complete captured', { data })
// Send a request to your backend to save the data
const status = await saveDataToBackend(data)
if (status === 'OK') {
// redirect user on successful
} else {
// If something goes wrong you can display an error towards the user on your end or redirect the user
}
}
function saveDataToBackend (data) {
return new Promise(function(resolve, reject) {
//The endpoint where the application will be processed.
const url = "https://[PARTNER].com/<your-endpoint>" //The url where you want to save your data
const res = await fetch(url, {
method: 'POST',
body: JSON.stringify(data)
})
if (res.ok) {
//Data loaded. Will show success message in Checkin.com module
resolve()
} else {
// Example on how to pass an error message into Checkin.com module
const errorMessage = 'Saving Error'
const errorType = 'unknown'
const error = new Error(errorMessage)
error.name = errorType
reject(error)
}
}
}
2. Create a new iOS ViewController:
Create a new ViewController class called GetIdViewController
. This should be linked to the view where you want to show the verification module.
import WebKit
class GetIdViewController : UIViewController, WKScriptMessageHandler {
override func viewDidLoad() {
super.viewDidLoad()
// Hide the navigation bar
self.navigationController?.isNavigationBarHidden = true
// Create the webview, setup module events listener, and load the module
let configuration = WKWebViewConfiguration()
configuration.allowsInlineMediaPlayback = true
configuration.userContentController.add(self, name: "onEvent")
let webView = WKWebView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height), configuration: configuration)
self.view.addSubview(webView)
let url = URL(string: "https://test.[PARTNER].com/native-test.html")
webView.load(URLRequest(url: url!))
}
override func viewWillDisappear(_ animated: Bool) {
// Show navigation bar when user leaves this view (closes module)
self.navigationController?.isNavigationBarHidden = false
super.viewWillDisappear(animated)
}
// Handler for Module state events. Ex open/close
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
if message.name == "onEvent" {
let data = message.body as! Dictionary<String, Any>
switch(data["action"] as! String) {
case "close-module":
self.navigationController?.popViewController(animated: true)
break
default:
break
}
}
}
}
3. Update your Info.plist
Info.plist
<key>NSCameraUsageDescription</key>
<string>Camera access is required for scanning your ID</string>
4. Launch the module with a button tap
Link a verification button on your UI to a function that will over the verification module ViewController:
func GetIdClicked() {
self.navigationController?.pushViewController(GetIdViewController(), animated: true)
}
API for verification results
You can find information about querying the API for verification statuses Here
Updated about 1 year ago