Implementation
Important Note!
Starting from version 5.0.0, the authentication system was updated to use a dynamic token instead of mobileToken. Before configuring the SDK, you must generate a temporary token through a server-to-server request to our Device Scan API.
import UIKit
import ZaigIosDeviceScan
class ViewController: UIViewController {
var zaigDeviceScan : ZaigIosDeviceScan?
override func viewDidLoad() {
super.viewDidLoad()
self.setupDeviceScan()
}
func setupDeviceScan() -> Void
{
// The environment can be 'sandbox' ou 'production'
let environment = "sandbox"
// MobileToken is the key sent to you by QI Tech. Each environment requires a different MobileToken.
let token = "TEMPORARY_TOKEN_FROM_DEVICE_SCAN_API"
// You must send the same session id in the moment of using the device scan and event analysis. It must be a key that uniquely identifies each user session in the app
let sessionId = "62715840-068a-4ded-a4e2-a1ec83f857d4"
do{
self.zaigDeviceScan = try ZaigIosDeviceScan(environment: environment, token: token, sessionId: sessionId)
}
catch{
print ("Error found when instantiating Zaigs DeviceScan")
}
let permissions = ["location"]
do{
try self.zaigDeviceScan?.requestPermissions(permissions: permissions)
}
catch{
print ("Error found when requesting Zaigs DeviceScan's permissions")
}
}
func onSuccess()
{
// Do something if QI Tech DeviceScan's collectData method succesfully collected device data
}
func onError()
{
// Do something if QI Tech DeviceScan's collectData method found any error when collecting device data
}
func collectZaigDeviceScanData()
{
// If you have your customer's document number (CPF or CNPJ without dots, hyphen or slash), you must sent it to QI Tech
let documentNumber = "12345678900"
// EventType must represent with type of interation the user had with your app on the moment that collectData method was called
let eventType = "login"
// EventId is your code that identifies the event sent to QI Tech
let eventId = "7038632032"
do{
try self.zaigDeviceScan?.collectData(documentNumber: documentNumber, eventId: eventId, eventType: eventType, onSuccessHandler: self.onSuccess, onErrorHandler: self.onError)
}
catch{
print("Error found when collecting Zaigs DeviceScan data")
}
}
}
To use the iOS Device Scan SDK, the following steps are required:
- Add the required permissions to the Info.plist file
- Add the framework to the app project
- When the app starts, instantiate the library with the appropriate parameters
- If your app has not yet requested the permissions from the user, request them through the
requestPermissionsfunction of the previously instantiated object - Collect and send the data using the
collectDatamethod