Classes

The following classes are available globally.

  • A collection of error codes related to the SDK authentication.

    See more
  • This class provides functionality to cancel pending promises. It is a source for cancellation tokens.

    The example below demonstrates how to retrieve a CancellationToken and use it to cancel a pending operation.

    let cancellationTokenSource = TKMCancellationTokenSource()
    let ct = cancellationTokenSource.token
    
    //Pass the token to an asynchronous operation that accepts a CancellationToken
    asyncOperation(..., ct).conclude()
    
    // If required, cancellation can be requested as follows:
    cancellationTokenSource.requestCancellation()
    

    See also

    TKMPromise<T>
    See more
  • Implementation of the promise pattern, used for composing async program flows. All asynchronous operations within the Tapkey Mobile SDK will return instances of this class.

    Promises allow waiting for the outcome of an operation in an async manner. Instead of waiting synchronously, callbacks, so called continuations, can be registered that are invoked on completion.

    Async functions returning promises can be composed to build async flows.

    Continuations are run on the TKMAsyncScheduler a promise was created with. Methods of this class that return a TKMPromise<T>, like continueOnUi(continuation:), catchOnUi(errorHandler:), etc., capture the TKMAsyncScheduler as returned by TKMAsyncSchedulers.current() at the time the method is called and associate it with the returned TKMPromise<T>.

    Most often promises are produced and continuations registered on the UI thread, which implies, that continuations will also run on the UI thread and subsequent TKMPromise<T>s are also associated with the UI thread. This is why functions for registering continuations contain the term ‘Ui’. Running all functionality on the UI thread makes synchronization between async functions very easy, because there is no multi-threading involved. This implies, however, that these functions may only run for a very short period of time in order not to compromise the user experience. Long running operations should be run on a separate worker thread by switching to an according TKMAsyncScheduler or by using TKMAsync.executeAsync(f:).

    The following exemplary code demonstrates an asynchronous method that returns a Promise.

    public func getStringAsync() -> TKPromise<String> {
        let promiseSource = TKMPromiseSource<String>()
    
        // Trigger a long-running operation
        getStringFromServer {(text: String?, optError: Error?) -> Void in
            if let error = optError {
                promiseSource.setError(error)
                return
            }
            promiseSource.setResult(text)
        }
        return promiseSource.promise
    }
    

    The example code below illustrates how to chain promises:

    getTextFromServer()
        .continueAsyncOnUi { text in
            return uploadTextToAnotherServer(text)
        }
        .continueOnUi { result in
            TKMLog.d(TAG, "Upload completed: \(result)")
            return nil
        }
        .catchOnUi { e in
            TKMLog.e(TAG, "Something went wrong.", e)
            return nil
        }
        .conclude()
    

    See also

    TKMAsync
    See more
  • Instances of this class are used to create and complete TKMPromise<T> instances. Instances of this class are produced with a reference to an TKMAsyncScheduler, which is used to invoke continuations on the returned TKMPromise<T>. By default, the current scheduler is captured when calling the constructor.

    See more
  • An TKMAsyncError represents an error that occurred during an asynchronous operation.

    See more
  • TKMError is used to represent errors inside many of the SDK’s components. To retrieve more information about the type of exception, the result of errorCode must be inspected.

    See more
  • A nearby Tapkey lock discovered via Bluetooth. Do not instantiate but use TKMBleLockScanner to get nearby Tapkey locks.

    See more
  • The result of a command, returned by a Tapkey lock. Contains a result code and additional response data.

    See more
  • Contains information about an error that occurred in a component inside the SDK.

    See more
  • A set of information on a locally available mobile key.

    See more
  • Reserved for internal use.

  • This class provides a Tapkey environment configuration. Unless suggested otherwise by Tapkey, this class must be used as shown below:

    // Within the UIApplicationDelegate.application(application:didFinishLaunchingWithOptions:)
    let environmentConfigBuilder = TKMEnvironmentConfigBuilder()
    let environmentConfig = environmentConfigBuilder.build()
    
    See more
  • This class is used to build a TKMServiceFactory.

    The example below illustrates a default use of this class and will cover most use cases:

     let b = TKMServiceFactoryBuilder()
     let tapkeyServiceFactory = b.build()
    

    See also

    TKMServiceFactory
    See more
  • Allows building an auto trigger lock command. This type of command lets the locking device choose the action to be performed based on the user’s key and the type of lock.

    Note, that locks running a older firmware don’t support automatic selection of the intended action type based on the user’s key and will therefore fall back to the lock’s default command. In order to stay backwards-compatible, it’s therefore suggested to use the CompatTriggerLockCommandBuilder instead of this class in most cases.

    See more
  • Allows building a trigger lock command that chooses the action to be performed based on the user’s permissions. The behavior of commands issued by instances of this class matches the one of AutoTriggerLockCommands which lets the lock choose the action to be taken. However, some locking devices (i.e. those implementing protocol version 0x3E) don’t support this kind of functionality. For these locking devices, instances of this class choose a concrete action type based on the permissions included in the user’s key.

    In most cases this class should be preferred over the AutoTriggerLockCommandBuilder. It should be used in cases, where the caller doesn’t know (or doesn’t want to know) anything about the concrete action to be taken. E.g. if the app offers the user a simple ‘unlock’ button, without giving the opertunity of distinguishing between different action types and without knowing much about the type of locking device, then this class should be used for building the TriggerLockCommand.

    The following table outlines the differences between DefaultTriggerLockCommandB, AutoTriggerLockCommandB and CompatTriggerLockCommandB:

     ==================================================   ============================= =============================================== =================================================
     Lock's Protocol Version                            | DefaultTriggerLockCommandB    AutoTriggerLockCommandB                         CompatTriggerLockCommandB
     ==================================================   ============================= =============================================== =================================================
     < 0x3E (locks only support the default command)    | Default command               Default command                                 Default command
     0x3E                                               | Default command               Default command                                 Builder chooses based on the user's permission
     >= 0x3F                                            | Default command               Lock chooses based on the user's permissions    Lock chooses based on the user's
     ==================================================   ============================= =============================================== =================================================
    
    See more
  • Allows building a custom trigger lock command. This type of command triggers a lock’s custom trigger lock action. A custom trigger lock action is specific to the locking device and usually only meaningful with corresponding custom command data.

    See more
  • Allows building a default trigger lock command. This type of command trigger’s the locking device’s default locking/unlocking action and is defined by the locking device itself. E.g. a standard door cylinder would usually unlock for a few seconds and allow the user to open the door during this time. Other locking devices might stay open indefinitely.

    The DefaultTriggerLockCommand is not to be confused with the AutoTriggerLockCommand. The former tries to trigger the lock’s default command independent of the user’s permissions. If the permissions don’t match, execution will fail. The latter lets the lock choose the action to be performed based on the user’s key and the locking device’s properties.

    Note, that lock running an older firmware may not support explicitly specifying the DefaultTriggerLockCommand. In order to stay backwards-compatible, it’s therefore suggested to use the CompatTriggerLockCommandBuilder instead of this class in most cases.

    See more
  • Allows building a permanent toggle command. The behaviour of this command depends on the state of the locking device. If the locking device is in an unlocked state, this command causes it to lock. If it’s in an locked state, it causes it to unlock indefinitely or until a certain point in time or for a certain duration.

    See more
  • Allows building a permanent unlock command. This type of command lets a locking device unlock indefinitely or until a certain point in time or for a certain duration.

    See more
  • Allows building a command for temporary unlocking. This type of command usually unlocks the locking device for just a few seconds that allow the user to open (e.g.) a door. This type of commands makes sense for doors that should stay locked and only open while someone passes.

    See more
  • Represents an observable object with a given type. The observable can be observed.

    See more