Implementing the callback
When you call the startIdentification method, you need to pass an AutomatIdCallback
object.
- Android
- iOS
tip
For Android, it is recommended to use the AutomatIdLifecycleCallback
subclass, that will ensure that its methods are invoked according to the lifecycle of the provided lifecycleOwner
(e.g. fragment), that is, only when your calling activity or fragment is brought back to the started state.
This is necessary, for example, to perform a fragment transaction or a navigation with Jetpack Navigation (androidx.navigation
).
AutomatIdManager.startIdentification(requireActivity(), identificationRequest, object : AutomatIdLifecycleCallback(this /* fragment */) {
override fun onSuccess_(result: AutomatIdIdentificationResult.Success) {
findNavController().navigate(HomeFragmentDirections.homeToFeedback(result))
}
override fun onCancel_() {
// no op
}
override fun onError_(error: AutomatIdIdentificationResult.Error) {
// Unrecoverable errors will always abort the identification flow, so we show a feedback screen.
findNavController().navigate(HomeFragmentDirections.homeToFeedback(error))
}
override fun decideRecoverableErrorHandling(error: AutomatIdIdentificationResult.Error): ErrorHandlingDecision {
return ErrorHandlingDecision.RETRY_IDENTIFICATION
}
})
AutomatIDCallback* callback = [[AutomatIDCallback alloc] init];
// optional, defaults to RETRY
callback.onRecoverableError = ^RecoverableErrorHandlingDecision(AutomatIDResultError * _Nonnull error) {
if (shouldAbortOnRecoverableError) {
return ErrorHandlingDecision_RETRY_SCI;
} else {
[self handleError:error];
return ErrorHandlingDecision_ABORT_SCI;
}
};
callback.onUnrecoverableError = ^void(AutomatIDResultError * _Nonnull error) {
[self handleError:error];
};
callback.onCancel = ^{
NSLog(@"user cancelled automatID");
};
callback.onSuccess = ^(AutomatIDResultSuccess * _Nonnull success) {
[self handleSuccess:success];
};