iOS library for integrating with Mesh Connect.
Add package LinkSDK in your project's Package Dependencies or download LinkSDK.xcframework.
Link token should be obtained from the POST /api/v1/linktoken endpoint. API reference for this request is available here. The request must be performed from the server side because it requires the client's secret. You will get the response in the following format:
{
"content": {
"linkToken": "{linkToken}"
},
"status": "ok",
"message": ""
}Create a LinkConfiguration instance with the linkToken and the callbacks:
let configuration = LinkConfiguration(
linkToken: linkToken,
settings: LinkSettings?,
disableDomainWhiteList: Bool?,
onIntegrationConnected: onIntegrationConnected,
onTransferFinished: onTransferFinished,
onEvent: onEvent,
onExit: onExit)The LinkSettings class allows to configure the Link behaviour:
accessTokens- an array ofIntegrationAccessTokenobjects that is used as an origin for crypto transfer flow;transferDestinationTokens- an array ofIntegrationAccessTokenobjects that is used as a destination for crypto transfer flow;language- a locale identifier for Link UI
The disableDomainWhiteList parameter is a boolean flag that allows to disable origin whitelisting. By default, the origin is whitelisted, with the predefined domains set
The AccessTokenPayload.integrationAccessToken(accountToken: AccountToken) function is used to convert an AccessTokenPayload to the IntegrationAccessToken object.
The callback onIntegrationConnected is called with LinkPayload once an integration has been connected.
let onIntegrationConnected: (LinkPayload)->() = { linkPayload in
switch linkPayload {
case .accessToken(let accessTokenPayload):
print(accessTokenPayload)
case .delayedAuth(let delayedAuthPayload):
print(delayedAuthPayload)
}
}The callback onTransferFinished is called once a crypto transfer has been executed or failed.
let onTransferFinished: (TransferFinishedPayload)->() = { transferFinishedPayload in
switch transferFinishedPayload {
case .success(let successPayload):
print(successPayload)
case .error(let errorPayload):
print(errorPayload.errorMessage)
}
}The callback onEvent is called to provide more details on the user's progress while interacting with the Link.
This is a list of possible event types, some of them may have additional parameters:
loadedintegrationConnectionErrorintegrationSelectedcredentialsEnteredtransferStartedtransferPreviewedtransferPreviewErrortransferExecutionError
The callback onExit is called once a user exits the Link flow. It might be used to dismiss the Link view controller in case the app manages its life cycle (see LinkHandler.create())
Callback closures are optional, but either onIntegrationConnected or onTransferFinished must be provided.
Create a LinkHandler instance by calling createHandler() function, or handle an error.
The following errors can be returned:
Invalid linkTokenEither 'onIntegrationConnected' or 'onTransferFinished' callback must be provided
let result = configuration.createHandler()
switch result {
case .failure(let error):
print(error)
case .success(let handler):
handler.present(in: self)
}In case of success, you can call LinkHandler.present(in viewController) function to let LinkSDK modally present the Link view controller and dismiss it on exit, or get the reference to a view controller by calling LinkHandler.create() if you prefer your app to manage its life cycle.