Integrating FastLink 3 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. FastLink 3 currently supports the US locale only. If the FastLink application is launched from a locale other than the US, a technical error will be given.
Integration Steps
Follow the steps to integratlet postString = "accessToken=Bearer {{Access_Token}}e FastLink in 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 need to 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 = "..."
guard let escapedExtraParams = extraParams.addingPercentEncoding(withAllowedCharacters: .alphanumerics) else { return }
let postString = "accessToken=Bearer {{Access_Token}}&app=10003600&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 this 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, addOns
, callback details, etc., can be passed as query parameters. Following is a sample code snippet for the add
deep-link flow.
...
let extraParams = "flow=add&providerId=16441"
guard let escapedExtraParams = extraParams.addingPercentEncoding(withAllowedCharacters: .alphanumerics) else { return }
...
For more details, refer to the Additional Params section in FastLink 3 Advanced Integration.
Handling Open Banking Sites
The intentUrl
attribute is used get the control back to the native app from an external application.
Pass intentURL
as part of extraParams
...
let extraParams = "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, authorizes consent, and completes the flow, the callback URL will be the intent URL which will be redirected to the intentUrl
.
Native app should listen to this intentUrl
by which 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 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 Messages
The FastLink application shares the account addition status to your application using the POST_MESSAGE
events.
{
"type": "POST_MESSAGE",
"data": {
//Post Message data
}
}