Implementation
Prerequisite for startDeviceScan
The startDeviceScan method requires a token. This token is temporary and must be generated on your backend by making a server-to-server request to our API before you call the SDK method.
Endpoint Details:
- Method: POST
- Path:
/device_scan/token - Sandbox URL:
https://d.sandbox.viewpkg.com/device_scan/token - Production URL:
https://d.viewpkg.com/device_scan/token
Headers:
{
"Authorization": "YOUR_DEVICE_SCAN_API_KEY"
}
Body:
{
"session_id": "unique_session_id"
}
The successful response from this API will contain the token that you must pass to the startDeviceScan method.
The device scan method can be executed asynchronously. Therefore, there is no need to block the main thread to wait for this method to resolve. The user can interact normally with the app while the device scan is being processed in the background.
We recommend that the device scan method is executed as early as possible. Since it may need more time to collect all data, this early call is recommended so that the most complete device information is extracted.
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:qitech_device_scan/qitech_device_scan.dart';
final _qitechDeviceScanPlugin = QitechDeviceScan();
// Step 1: Generate the temporary token via a server-to-server request
Future<String?> fetchDeviceScanToken(String sessionId) async {
final response = await http.post(
Uri.parse('<DEVICE_SCAN_API_URL>'),
headers: {
HttpHeaders.authorizationHeader: '<API_KEY>',
HttpHeaders.contentTypeHeader: 'application/json',
},
body: jsonEncode({'session_id': sessionId}),
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
return data['token'] as String?;
}
return null;
}
// Step 2: Initialize the SDK with the obtained token
final sessionId = '<SESSION_ID>';
final token = await fetchDeviceScanToken(sessionId);
if (token == null) {
print('Failed to fetch device scan token');
return;
}
final result = await _qitechDeviceScanPlugin.startDeviceScan(
token: token,
environment: CaaSEnvironment.sandbox,
sessionId: sessionId,
eventType: '<EVENT_TYPE>',
eventId: '<EVENT_ID>',
);
print('Device Scan result: $result');
Flutter Setup
To use the device scan plugin, the following steps are required:
Installation
First, run the following command to install the plugin:
flutter pub add qitech_device_scan
The command should install the latest version, which can be checked in your pubspec.yaml file:
dependencies:
qitech_device_scan: ^1.0.0
http: ^1.0.0
Import
Now, just import the package to start using it:
import 'package:qitech_device_scan/qitech_device_scan.dart';
Android Setup
Add the Qi Tech Android repository reference in your build.gradle file:
allprojects {
repositories {
maven { url 'https://sdks.zaig.com.br/' }
...
}
}
Initialize the AdMob service by adding the following code to your AndroidManifest.xml:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="<ADMOB_APP_ID>"/>
If you do not have an ADMOB_APP_ID, contact suporte.caas@qitech.com.br.
iOS Setup
Add the Qi Tech iOS repository reference in your Podfile:
source 'https://cdn.cocoapods.org/'
source 'https://github.com/ZaigCoding/iOS.git'
Install dependencies directly via CocoaPods:
cd ios
pod install
or via Flutter:
flutter build ios