How to integrate

Lean's iOS SDK is available through Swift Package Manager. To integrate Lean’s Link SDK in XCode go to File > Swift Packages > Add Package Dependency and use the URL below:

https://www.github.com/leantechnologies/link-sdk-ios-distribution

Manual installation can also be achieved by adding the .xcframework available here to your project in Xcode.

You can then import the SDK into your swift files.

import LeanSDK

Usage with Swift UI

1. Initalizing

You will need to initalize the LeanSDK within your Swift UI application by calling Lean.manager.setup(appToken, sandbox), version this sets the application token and environment during runtime of your application.

// YourApp.Swift

import SwiftUI
import LeanSDK

@main
class LeanTestAppApp: App {

    required init() {
        Lean.manager.setup(
            appToken: String,
            sandbox: true,
            version: "latest"
        )
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

2. Create the View state

You can present a Lean.manager.view anywhere in your application, however for best performance we recommend that it be placed inside a .fullScreenCover and set ignoresSafeArea() so that the view displays in full screen.

// ContentView.swift

import SwiftUI
import LeanSDK

struct ContentView: View {
    @State private var isPresented = false
    var linkPermissions = [LeanPermission.Identity, LeanPermission.Accounts,
                       LeanPermission.Transactions, LeanPermission.Balance]

    var body: some View {
        VStack {
            Button("Link", action: { handleLink() })
        }
    }
    .fullScreenCover(isPresented: $isPresented, content: {
        Lean.manager.view.ignoresSafeArea()
    })

    func handleLink() {
        Lean.manager
                .link(customerId: String, permissions: linkPermissions, customization: LeanCustomization?, success: {
                    print("Entity Linked")
                    isPresented = false
                }, error: { (status) in
                    print(status.status)
                    print(status.message)
                    print(status.method)
                    isPresented = false
                })
        isPresented = true
    }
}

3. Call a method

You can now write and attach functions to any UI element using Lean.manager.[method] see Methods section below

4. Handle success and error closures

You can write your own completion blocks upon success and failure of the LinkSDK.

Errors will pass back a LeanStatus dictionary with the following:

{
    status: "ERROR",
    method: "LINK",
    message: "Some message"
}

Usage with View Controllers

Initalizing

Call Lean.manager.setup(appToken, sandbox, version) during ViewDidLoad - or before attempting to make a call to the SDK.

// ViewController.swift

import UIKit
import LeanSDK

class ViewController: UIViewController {

    override func ViewDidLoad() {
        super.viewDidLoad()
        Lean.manager.setup(appToken: String, sandbox: true, version: "latest")
    }
}

Call a method

You can now write and attach functions to any UI element using Lean.manager.[method] see Methods section below.

Ensure that you set the presentingViewController, to the View Controller that you want the SDK to present within.

// ViewController.swift

import UIKit
import LeanSDK

class ViewController: UIViewController {
    var connectPermissions = [LeanPermission.Identity, LeanPermission.Accounts,
                              LeanPermission.Transactions, LeanPermission.Balance]

    override func ViewDidLoad() {
        super.viewDidLoad()
        Lean.manager.setup(appToken: String, sandbox: true, version: "latest")
    }
}
    @IBAction func handleLink(_sender: Any) {
        Lean.manager.connect(
            presentingViewController: self,
            customerId: String,
            permissions: connectPermissions,
            bankId: nil,
            customization: LeanCustomization?,
            success: { status in
                print("Entity Linked")
            }, error: { (status) in
                print(status)
            }
        )
    }

Handle success and error closures

You can write your own completion blocks upon success and failure of the LinkSDK.

Errors will pass back a LeanStatus dictionary with the following:

{
    status: "ERROR",
    method: "LINK",
    message: "Some message"
}

Choosing a version

When calling Lean.manager.setup a version is required.

Version takes a String and can point to either a specific SDK version i.e. "latest" or an alias i.e. "latest".

Lean.manager.setup(
    appToken: String,
    sandbox: true,
    version: "latest"
    )

📘

We recommend passing in a specific version to ensure stability in the case that a change to the SDK breaks your application.

Available Versions

Specific Version semver

The current stable build is 1.25.0

latest alias

latest is an alias for the current release. It is subject to change at relatively short notice - but does allow for any bug fixes to be shipped over the air - meaning fixes can be applied without the need to resubmit your application to the app store.

next-release alias

next-release is a QA version of the SDK allowing you to test the next version that will become latest before we roll out the changes, this should only be used for development and QA purposes as it is subject to breakage without any warning.

Available Methods

.connect()

The connect method is used to enable a customer to use a single log in to create and Entity and a PaymentSource for use with the Data API and Payments API respectively.

Lean.manager.connect(
    customerId: String,
    permissions: ArrayOf<LeanPermission>,
    paymentDestinationId: String,
    bankId: String?
    customization: LeanCustomization?,
    success: () -> (),
    error: (status) -> ()
)

.reconnect()

The reconnect method is used to re-authenticate a customer account with the Data API.

Lean.manager.reconnect(
    reconnectId: String,
    customization: LeanCustomization?,
    success: () -> (),
    error: (status) -> ()
)

.createPaymentSource()

The createPaymentSource method is used to connect a bank account as a payment method to your application in the Payments API.

Lean.manager.createPaymentSource(
    customerId: String,
    bankId: String?,
    customization: LeanCustomization?,
    success: () -> (),
    error: (status) -> ()
)

.updatePaymentSource()

The updatePaymentSource method is used to authorise an additional payment destination for an existing payment source in the Payments API.

Lean.manager.updatePaymentSource(
    customerId: String,
    paymentSourceId: String,
    paymentDestinationId: String,
    customization: LeanCustomization?,
    success: () -> (),
    error: (status) -> ()
)

.pay()

The pay method is used to make a bank to bank transfer from your customer's account to your account in the Payments API.

Lean.manager.pay(
    paymentIntentId: String,
    accountId: String?
    customization: LeanCustomization?,
    success: () -> (),
    error: (status) -> ()
)

Changing the SDK language

Link SDK is available in English and Arabic, fully supported with a right-to-left UI, including text alignment, icons and images. If no language is provided the default is English. The language parameter is provided to the Lean.manager.setup

...
Lean.manager.setup(
    language: String,
    ...
)

Language option

language enum

enEnglish
arArabic

Customizing Link SDK

We are progressively releasing customization capabilities to the Link SDK to match its UI with your application branding style. This allows customers to programmatically theme the Link SDK directly from any of the methods.

For more detailed documentation on how best to use the customization feature see our guides.

Customisation Guide

Presentation options

dialog_mode string

Presents the Link SDK with or without a containing modal.

"contained" for modal (default), or "uncontained" for no modal.

button_border_radius string

Change the shape of the main button on each step. See guidance for examples.

A unitless number as a String. Options:

ValueStyle
"4"default
"8"Border radius of 8px
"0"Rectangle button
"pill"Always pill shaped, whatever the button height

Color options

theme_color string

Buttons background color, active input borders, and loading spinners.

button_text_color string

Elements inside any primary button such as the text, icons and the loading spinner. It is useful to boost readability of the button color.

link_color string

CTAs and helpers.

overlay_color string

Overlay containing the Link SDK dialog box.

The following color formats are supported:

ExampleFormat
"#000000"Hex
"#000"Shorthand hex
"#000000FF"Hex with alpha
"rgb(0, 0, 0)"Comma separated RGB
"rgba(0, 0, 0, 0.5)"Comma separated RGB with Alpha
"black"Color name

Example

var customConfig = LeanCustomization(
    dialogMode: String?, 
    themeColor: String?, 
    buttonTextColor: String?,
    buttonBorderRadius: String?,
    linkColor: String?, 
    overlayColor: String?
)

Lean.manager.connect(
    customerId: String,
    permissions: ArrayOf<LeanPermission>,
    paymentDestinationId: String,
    bankId: String?
    customization: customConfig,
    success: () -> (),
    error: (status) -> ()
)

Did this page help you?