unlock

fun unlock(credentialId: <Error class: unknown class>, unlockProximity: UnlockProximity? = null, timeout: Duration? = null): Job

Unlocks the app user's phone.

Initiates an unlock operation for the specified credential. Progress events are emitted to unlockStatus StateFlow. The operation continues even if the app goes to background.

Works offline if credentials are already cached. Requires the device to have the necessary hardware (Bluetooth, NFC, etc.) and permissions granted.

val seamSDK = SeamSDK.getInstance()
// Start collecting unlock events before unlock
coroutineScope.launch {
seamSDK.unlockStatus.collect { event ->
when (event) {
is SeamUnlockEvent.ScanningStarted -> { /* handle scanning started */}
is SeamUnlockEvent.Connecting -> { /* handle connecting */}
is SeamUnlockEvent.AccessGranted -> { /* handle access granted */}
is SeamUnlockEvent.Timeout -> { /* handle timeout */}
is SeamUnlockEvent.ReaderError -> { /* handle reader error */}
else -> { /* handle other events */}
}
}
}

// Perform unlock
try {
val credentialId = credential.id
// Timeout is optional
seamSDK.unlock(
credentialId = credentialId,
unlockProximity = UnlockProximity.TOUCH,
timeout = 30.seconds
)
} catch (seamError: SeamError) {
when (seamError) {
is SeamError.ActivationRequired -> {
// handle error when SDK is not activated
}
is SeamError.CredentialErrors -> {
val credentialErrors = seamError.errors
handleCredentialErrors(credentialErrors)
// handle error when there are credential errors
}
is SeamError.InitializationRequired -> {
// handle error when SDK is not initialized
}
is SeamError.IntegrationNotFound -> {
// handle error when integration is not found, Such as Assa Abloy, Latch and Salto
}
is SeamError.InternetConnectionRequired -> {
// handle error when internet connection is required
}
is SeamError.InvalidClientSessionToken -> {
// handle error when client session token is invalid
}
else -> {
// handle other errors
}
}
}

// Handle credential errors on unlock
fun handleCredentialErrors(credentialErrors: List<SeamCredentialError>) {
credentialErrors.forEach { credentialError ->
when (credentialError) {
is SeamCredentialError.Invalid -> {
// handle error when credential is invalid
}

is SeamCredentialError.Expired -> {
// handle error when credential is expired
}

is SeamCredentialError.Loading -> {
// handle error when credential is not loaded yet
}

is SeamCredentialError.UserInteractionRequired -> {
// handle user interaction required credential error
}

is SeamCredentialError.Unknown -> {
// handle unknown credential error
}
}
}
}

Return

a Job that can be used to cancel the unlock operation.

Parameters

credentialId

the credential ID to unlock. CredentialId is a type alias for String.

timeout

the timeout for the unlock operation. If null, uses provider default.

unlockProximity

the unlock proximity UnlockProximity. If null, uses provider default, which is the first in the list of SeamCredential.supportedUnlockProximities. The SeamCredential must have at least one supported unlock proximity.

Throws

if the SDK has not been initialized yet.

if the device is offline.

if the integration is not found.

if the client session token is invalid.

if the app user's phone has not been activated yet.

if the credential has unresolved errors.