iOS Integration

Synaps integrates its workflow easily on iOS devices without extra packages or SDK. Thanks to SFSafariViewController component, iOS lets you access our iframe integration easily. Here is a guided tour of how integrating Synaps on native iOS.

iOS Workflow

The iOS navigation workflow can be separated in 4 steps.

1. Create a Synaps app

To start, you need to create an app. After logged in to your Synaps Manager interface, just click on New app. Go to integration tab and copy your Synaps API Key

2. Integrate Synaps Sessions with your Private API

As you are dealing with a mobile app, no sensitive information should appear on it. You should store no credentials, passwords, API Keys directly in your mobile codebase as it can easily be accessed by anyone.

The most common way to deal with sensitive information is to call your Private API and set a authorization mechanism using access token for instance. This mechanism will lets you call the API with a time-based token and will keep every sensitive data in your backend.

Synaps API Key is a sensitive information. This key will lets you generate new verification sessions and access sessions information.

Synaps Session ID is not a sensitive information. This Session ID has been built for front-end. It can be exposed publicly without any problem because it exposes no user information. It has been designed to only upload information.

As you are designing an iOS app and as it is considered as a front-end (publicly accessible), your goal is to call your private API that will generates a Synaps Session ID for you.

3. Integrate Synaps Flow with SFSafariViewController to your app

SFSafariViewController has been introduced in 2015 by Apple and lets you open a Safari Modal easily on your app. As Safari is the most easiest way to get access to devices capabilities such as camera, Synaps integrates very well with it. It is compatible with iOS 9+ and is part of the SafariServices framework.

We are going to design a simple view of an app where we will be able to open up the Synaps Flow in a SFSafariViewController modal.

  1. Create a Single View App using Xcode

Once your app is created, go to the Main.storyboard and add a Verify with Synaps button. We are going to trigger its action to open up our modal.

2. Integrate SFSafariViewController in your View Controller

Go to your ViewController.swift and add the following code to your controller

//
// ViewController.swift
// sample-demo-kyc
//
// Created by Riwan Lasmi on 01/07/2020.
// Copyright © 2020 Synaps. All rights reserved.
//
import UIKit
import SafariServices
class ViewController: UIViewController, SFSafariViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func openSynaps(_ sender: Any) {
/* Retrieve Synaps Session ID via your Private API*/
let synapsSession: String = "https://verify.synaps.io/?session_id=f854a787-aeef-472f-98f4-c0f5309b&service=workflow&type=embed&mobile=ios"
showSafariVC(for: synapsSession)
}
func showSafariVC(for url: String) {
guard let url = URL(string: url) else {
return
}
let safariVC = SFSafariViewController(url: url)
safariVC.delegate = self
safariVC.modalPresentationStyle = .popover
present(safariVC, animated: true)
}
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
/* Replace this alert with your Business Logic */
let alert = UIAlertController(title: "Synaps", message: "Pull data from Synaps API using your Private API", preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}

We can notice 3 importants functions

openSynaps - Triggers the "Verify with Synaps" button and cal the showSafariVC that will open up the page.

@IBAction func openSynaps(_ sender: Any) {
/* Retrieve Synaps Session ID via your Private API*/
let synapsSession: String = "https://verify.synaps.io/?session_id=f854a787-aeef-472f-98f4-c0f5309b&service=workflow&type=embed&mobile=ios"
showSafariVC(for: synapsSession)
}

showSafariVC - Opens the URL in a Safari Modal

func showSafariVC(for url: String) {
guard let url = URL(string: url) else {
return
}
let safariVC = SFSafariViewController(url: url)
safariVC.delegate = self
safariVC.modalPresentationStyle = .popover
present(safariVC, animated: true)
}

safariViewControllerDidFinish - Triggered when a user click on the "Done" button

func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
/* Replace this alert with your Business Logic */
let alert = UIAlertController(title: "Synaps", message: "Pull data from Synaps API using your Private API", preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}

3. Build your Synaps Session Link

You can see in the following code block that the Synaps Session Link is static. Let's see how to build it dynamically.

@IBAction func openSynaps(_ sender: Any) {
/* Retrieve Synaps Session ID via your Private API */
/* Build your Synaps Sesion Link according to the following available query parameters */
let synapsSession: String = "https://verify.synaps.io/?session_id=f854a787-aeef-472f-98f4-c0f5309b&service=workflow&type=embed&mobile=ios"
showSafariVC(for: synapsSession)
}
https://verify.synaps.io
Request
Response
Request
Path Parameters
optional
string
Query Parameters
mobile
required
string
As your are on iOS platform simply add ios as query parameter
type
required
string
There is two mode of UI embed - full screen modal - part of your screen For mobile integration, we strongly required embed mode
service
required
string
The service name based on your subscription workflow phone liveness identity residency
session_id
required
string
Session ID previously pulled using your Private API and associated to your current user
Response
200: OK

The Synaps Session Link will remains approximately always the same only session_id and service parameters will change for iOS integration.

https://verify.synaps.io/?session_id={SESSION_ID}&service={SESSION_SERVICE}&type=embed&mobile=ios

4. Pull data from Synaps API once user is onboarded

The following function will be triggered once the user click on the "Done" button in the Safari Modal.

func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
/* Call Private API to pull user data */
}

The most common thing done at this time is to call the app's Private API to retrieve user information. Once onboarded, your Private API will have access to the current Session ID resource by calling our Synaps API using both Session ID and Api Key.

4. Integration Result

Once everything is implemented you should see something like this. (video download link)

If you have any technical question, don't hesitate to reach riwan@synaps.io