实现
重要提示!
从版本 5.0.0 开始,认证系统已更新为使用动态 token 替代 mobileToken。在配置 SDK 之前,您必须通过向我们的 Device Scan API 发送服务器间请求来生成临时 token。
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")
}
}
}
要使用 iOS Device Scan SDK,需要执行以下步骤:
在 Info.plist 文件中添加权限
将框架添加到应用程序项目
在应用程序启动时,实例化库,并传入适当的参数
如果您的应用程序尚未向用户请求权限,请通过之前实例化的对象的 requestPermissions 函数向用户请求权限
通过 collectData 方法收集并发送数据