Sorry, you need to enable JavaScript to visit this website.
Skip to main content

Integrating FastLink 4 for iOS

FastLink can be integrated into your iOS application through WebView. Prerequisites to integrate FastLink are iOS 8.0+ and WKWebView, as the App Store will no longer accept new apps using UIWebView from April 2020 and apps that are updated using UIWebView as of December 2020.

Integration Steps

Follow the steps to integrate FastLink into an iOS application. The code samples here use the Swift language. FastLink can equally be loaded from the corresponding Objective C code.

Step 1: Generate an Access Token

FastLink uses the client credentials authentication mechanism. You must pass a valid accessToken to authenticate your invocation of the FastLink application. Generate the access token by following the instructions provided in the Getting Started with Client Credentials page.

Step 2: Create the WKWebView Instance

You can either programmatically create the WkWebView instance or add it through the Interface Builder. Import the WebKit module and inherit the WKUIDelegate and WKNavigationDelegate classes to the WkWebView instance.

import UIKit
import WebKit

class FastLinkViewController: UIViewController, WKUIDelegate, WKNavigationDelegate {

    @IBOutlet weak var webview: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()

        self.webview.uiDelegate = self
        self.webview.navigationDelegate = self
        ...
    }
}

Step 3: Create the Request Object

Once the WKWebView instance is created, you have to create the request object.

guard let url = URL(string:"{{FastLink_URL}}") else { return }
var request = URLRequest(url: url)

request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")

request.httpMethod = "POST"

let extraParams = "configName=<config-name-from-config-tool>"

guard let escapedExtraParams = extraParams.addingPercentEncoding(withAllowedCharacters: .alphanumerics) else { return }

let postString = "accessToken=Bearer {{Access_Token}}&amp;extraParams=" + (escapedExtraParams)  ??  “”

request.httpBody = postString.data(using: .utf8)

Step 4: Load the Request Object in the WKWebView Instance

Once the request object is ready, load it in the WKWebView instance. This will render the FastLink inside WKWebView.

self.webview.load(request)

Passing Additional Params to FastLink

While creating the request object, additional params like deep-linking flow attributes, callback details, etc., can be passed as query parameters along with the mandatory configName parameter. Following is a sample code snippet for the add deep-link flow.

...
let extraParams = "configName=<config-name-from-config-tool>&flow=add&providerId=16441"
guard let escapedExtraParams = extraParams.addingPercentEncoding(withAllowedCharacters: .alphanumerics) else { return }
...

For more details, refer to the Additional Params section in FastLink 4 Advanced Integration.

Handling Open Banking Sites

The intentUrl attribute is used get the control back to the native app from an external application. Example, native browser.

Passing intentUrl as part of extraParams

...
let extraParams = "configName=<config-name-from-config-tool>&intentUrl=<protocol://domainname>"
guard let escapedExtraParams = extraParams.addingPercentEncoding(withAllowedCharacters: .alphanumerics) else { return }
...

When the user selects an Open Banking site, FastLink will send a post message with the site's OAuth URL which needs to be opened in a native browser.

Post Message - OPEN_EXTERNAL_URL

{
    "type": "OPEN_EXTERNAL_URL",
    "data": {
        "url": "<OAUTH URL>"
    }
}

Once the user logs in, authorize consent, and completes the flow, use intentUrl as callback URL.

Native app should listen to this intentUrl by which the control comes back to the native app.

Handling Callback

Entries in info.plist.

<?xml version="1.0" encoding="UTF-8"?>
   <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleURLName</key>
			<string><protocol://domainname></string>
			<key>CFBundleURLSchemes</key>
			<array>
				<string><protocol></string>
			</array>
		</dict>
	</array>
</dict>
</plist>

Handling Events from FastLink

To communicate with the events from FastLink, your application has to listen for the WKScriptMessageHandler delegate method. Note that the name should be YWebViewHandler as FastLink will check for this name and send the events.

//Delegate method for WKScriptMessageHandler
extension CUSTOMER_APP_VIEW_CONTROLLER: WKScriptMessageHandler {
    func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        if(message.name == "YWebViewHandler") {
            let messageBody = message.body as? String
            print(messageBody)
        }
    }
}

Add the userContentController config to the WebView instance.

self.webview.configuration.userContentController.add(self, name: "YWebViewHandler")

Post Message Events

The FastLink application shares the account addition status to your application using the POST_MESSAGE events.

{
    "type": "POST_MESSAGE",
    "data": {
        //Post Message data
    }
}

External URL

You must open the URL in the SFSafariViewController, SFAuthenticationSession, ASWebAuthenticationSession, or in the default mobile browser. You MUST NOT open the external URL within a WKWebView. Doing so will result in blocked requests from many data providers due to security vulnerabilities.

{
    "type": "OPEN_EXTERNAL_URL",
    "data": {
        "url": "<External URL>"
    }
}