Scan Process - iOS
The Anyline Tire Tread SDK allows for a variety of options on how to set up the scan process. In the following sections we will show the most convenient and quick way to get started with scanning.
|
You can check out our iOS GitHub repository for a complete example implementation of the scan flow. |
Setting up the scanner
Once the SDK has been initialized and the necessary permissions have been granted, you can start a scan.
This example uses the typed scan(from:config:) overload. If you want the default behavior, pass TireTreadConfig() unchanged.
private func startScan() {
let scanner = AnylineTireTreadScanner()
let customConfig = TireTreadConfig()
/* if needed, you can customize the config, e.g.: */
// customConfig.uiConfig.measurementSystem = .imperial
// customConfig.uiConfig.tapToStartScanningTooltipConfig.textOk = "Start scanning now"
scanner.scan(from: self, config: customConfig) { outcome in
handleOutcome(outcome)
}
}
private func handleOutcome(_ outcome: ScanOutcome) {
if let completed = outcome as? CompletedOutcome {
openResultScreen(uuid: completed.measurementUUID)
} else if outcome is AbortedOutcome {
dismiss(animated: true)
} else if let failed = outcome as? FailedOutcome {
showError(failed.error)
}
}
When scan() returns a FailedOutcome, inspect the returned SdkError and handle it as described on the Error Handling page.
For the typed API shown above, pass a TireTreadConfig. If you prefer not to create one, iOS also offers scan(from:completion:) for the default configuration.
Setup with JSON config
You can also load the scan configuration from a JSON file in your bundle and pass it through the configJson parameter.
private func startScanFromJson() {
let scanner = AnylineTireTreadScanner()
guard
let url = Bundle.main.url(forResource: "my_scan_config", withExtension: "json"),
let jsonConfig = try? String(contentsOf: url, encoding: .utf8)
else {
return
}
scanner.scan(from: self, configJson: jsonConfig) { outcome in
handleOutcome(outcome)
}
}
If you already have the JSON content as a string, you can pass that string directly to configJson.
Check out the next section to learn how to handle the measurement results after the scan process is finished.