Skip to content

Mobile Keys

A Mobile Key is a short-lived key (usually several days) issued based on a Grant and can be used for unlocking. Mobile Keys are cached by the Tapkey Mobile SDK for iOS, so they can be used for unlocking even if the mobile device is offline. To ensure that Mobile Keys are always up to date, they need to be periodically renewed, which usually happens in the background. It is recommended to configure Push Notifications for this purpose.

For more details on keeping Mobile Keys in sync, please refer to the section Keep data up to date.

The TKMKeyManager, obtained through the TKMServiceFactory, provides access to the Mobile Keys.

let keyManager = tapkeyServiceFactory.keyManager

To retrieve a list of Mobile Keys, you can use the method getLocalKeys(userId: String). These Mobile Keys are locally stored and available offline. Calling this method does not trigger a refresh.

let localKeys: [TKMKeyDetails] = keyManager.getLocalKeys(userId: userId)

To retrieve a specific Mobile Key for a lock, you can use the method getLocalKey(userId: String, grantId: String, physicalLockId: String).

let localKey: [TKMKeyDetails] = keyManager.getLocalKey(userId: userId, grantId: grantId, physicalLockId: physicalLockId)

To react to changes in the Mobile Keys, you can obtain an observable using the property keyUpdateObservable.

let observableRegistration = keyManager.keyUpdateObservable.addObserver { keyChangedNotification in
    // ToDo: React based on the event
}

// Close observable if not needed anymore
observableRegistration.close()