LockKit

public class LockKit

This is the main interface of the framework.

It provides LockKit.shared singleton that can be used to communicate with Donkey locks, i.e. unlocking, locking and ending a rental.

  • The singleton instance of LockKit.

    Declaration

    Swift

    public static let shared: LockKit

Initialization and configuration

  • Configure Lock Kit according to configuration.

    Declaration

    Swift

    public func configure(_ configuration: LockKitConfiguration)

    Parameters

    configuration

    The LockKitConfiguration object that provides global configuration for Donkey Lock Kit.

  • Initialize the SDK with the provided apiToken.

    This method should be called before any other interaction with the SDK. It sets up the LockKit instance and verifies the provided token. The token must be valid in order for LockKit to work.

    Important

    The SDK Token used by Donkey Lock Kit is different from the API Key used for server-to-server communication. Passing your server-to-server API Key to this method won’t work. You need to contact Donkey Republic to have your SDK Token issued.

    Note

    Make sure that you use the correct SDK Token for the environment the LockKit is set up with. The test environment tokens won’t work in live environment, and vice versa. If needed, adjust the environment by calling LockKit.configure(...) with an appropriate configuration.

    Declaration

    Swift

    public func initializeSDK(
        sdkToken: String,
        onResult: @escaping (Result<Void, InitializeSDKError>) -> Void
    )

    Parameters

    sdkToken

    Your LockKit SDK Token, as issued by Donkey Republic.

    onResult

    A handler that is called when the initialization finishes.

Communicating with BLE locks

  • Initialize a BLE Lock for use with the SDK.

    This method takes BLE Lock’s e-key and passkey and stores them internally for use in subsequent calls to lock(...), unlock(...) and prepareEndRental(...).

    Declaration

    Swift

    public func initializeLock(
        lockName: LockName,
        eKey: String,
        passkey: String
    ) -> Result<Void, InitializeLockError>

    Parameters

    lockName

    name of the lock (e.g. AXA:0123456789abcdef)

    eKey

    the valid e-key for the lock

    passkey

    the passkey associated with the provided e-key.

  • Unlock a BLE lock with a given lockName.

    This method requires that the lock was previously initialized by calling initializeLock(...).

    Declaration

    Swift

    public func unlock(
        lockName: LockName,
        onStatusChanged: @escaping (StatusUpdate) -> Void,
        onResult: @escaping (Result<Void, LockError>) -> Void
    )

    Parameters

    lockName

    name of the lock (e.g. AXA:0123456789abcdef)

    onStatusChanged

    callback that can be called multiple times during the unlock operation, providing updates on the progress.

    onResult

    callback that is called after the operation completes. It takes a Result parameter that can contain an error in case the operation failed.

  • Lock a BLE lock with a given lockName.

    This method requires that the lock was previously initialized by calling initializeLock(...).

    Declaration

    Swift

    public func lock(
        lockName: LockName,
        onStatusChanged: @escaping (StatusUpdate) -> Void,
        onResult: @escaping (Result<Void, LockError>) -> Void
    )

    Parameters

    lockName

    name of the lock (e.g. AXA:0123456789abcdef)

    onStatusChanged

    callback that can be called multiple times during the unlock operation, providing updates on the progress.

    onResult

    callback that is called after the operation completes. It takes a Result parameter that can contain an error in case the operation failed.

  • Lock a BLE lock and prepare it for ending a rental.

    This method requires that the lock was previously initialized by calling initializeLock(...). It performs the same action as lock(...) but adds an extra check in order to confirm that the vehicle is ready for ending a rental.

    Note

    This method does not end the rental. Most importantly, it does not communicate with Donkey Republic servers. You are still responsible for ending the rental using TOMP server API. What this method does is it sends the lock command to the lock and ensures that the lock is closed and secured and the vehicle is ready for the rental to be ended.

    Declaration

    Swift

    public func prepareEndRental(
        lockName: LockName,
        onStatusChanged: @escaping (StatusUpdate) -> Void,
        onResult: @escaping (Result<Void, LockError>) -> Void
    )

    Parameters

    lockName

    name of the lock (e.g. AXA:0123456789abcdef)

    onStatusChanged

    callback that can be called multiple times during the unlock operation, providing updates on the progress.

    onResult

    callback that is called after the operation completes. It takes a Result parameter that can contain an error in case the operation failed.

  • Clean up and deinitialize a lock.

    This method disconnects from the lock and removes any references to it.

    Declaration

    Swift

    public func finalizeLock(
        lockName: LockName
    ) -> Result<Void, FinalizeLockError>

    Parameters

    lockName

    name of the lock (e.g. AXA:0123456789abcdef)

    Return Value

    FinalizeSuccess upon successful initialization, or FinalizeLockError when the intialization failed.