Summary

Due to the asynchronous nature of the PrivakeyCX library, it utilizes Protocols to return the results of many of the library's methods. There are 2 primary protocols that you may implement: delegate and uiDelegate. They are described below.


Delegate

The delegate property is of protocol type PrivakeyCXDelegate, and has multiple functions that you can implement depending on what delegation you want to perform. Note that Swift Protocols require all methods to be implemented, but you can leave a method blank if you don't want to actually handle it.

Below is a list of the PrivakeyCXDelegate methods, and when they are called.

checkAccountStatus

func checkAccountStatus ( didBecomeActive: Bool?, wasPinAttemptRevoked: Bool? )

Called when an error occurs while calling the CX Server. This may indicate that your account or device status has changed and needs to be checked and possibly resolved. Call getCurrentDevice() to get the status of the device and account. This function receives the following parameters:

  • didBecomeActive: True if the account has just become active.
  • wasPinAttemptRevoked: True if the device was revoked because of exceeding invalid PIN attempts.

onFailedPassword

func onFailedPassword ( attemptsRemaining: Int )

Called when a failed password attempt was made. attemptsRemaining is the number of failed attempts that can be made before the device is revoked.


onRequestStatusUpdated

func onRequestStatusUpdated ( request: PKRequest )

Called when a request is acted on or changes in status. request is the request with the new status information.


accountUpdated

func accountUpdated ( account: PrivakeyAccount )

Called when account information has been updated. account is the updated account.


deviceUpdated

func deviceUpdated ( device: PrivakeyDevice )

Called when device information has been updated. device is the updated device.


onNewRequest

func onNewRequest ( request: PKRequest )

Called when a new request is ready to be acted on. request is the new request.


onGetRequestsResult

func onGetRequestsResult ( appSpaceGuid: String, requests: [PKRequest], error: String? )

When getRequestByGuid() or getRequests() are called, they immediately return the cached requests that match the criteria, if they exist. At the same time, the library also calls to the CX Server to get the most up-to-date request data. When that network call finished, onGetRequestsResult() is called if there was cache returned. It received the following parameters:

  • appSpaceGuid: GUID of the App space these requests belong to.
  • requests: List of Requests that match the search criteria.
  • error: If something goes wrong, this object will tell you what.

onBiometricResult

func onBiometricResult ( result: String )

Returns the result of an attempted biometric reading. result is a string describing the result of the operation.


onDeviceRevoked

func onDeviceRevoked ()

Called when the device is revoked.

UI Delegate

The uiDelegate property is of protocol type PinEntriesManagerUIDelegate, and has only a single function. This is so you can easily update your UI to respond to failed PIN entries.

pinEntry

func pinEntry ( attemptsLeft: Int )

Returns any time a failed PIN entry was performed. It is recommended to warn the user when they have 1 attempt left to prevent the device from being revoked.