iOS

Seamless Transak integration for iOS applications
View as Markdown

The Transak iOS integration allows you to embed a fully functional interface directly into your native iOS application using Webview.

1

Add Camera Permission

Update your Info.plist to include camera permission (required for KYC verification):

1<key>NSCameraUsageDescription</key>
2<string>Permission required for Camera Access.</string>
2

Implement WebView in View Controller

Configure your View Controller to load the Transak widget URL using your preferred implementation:

1import SwiftUI
2import WebKit
3
4struct WebView: UIViewRepresentable {
5 let url: URL
6
7 func makeUIView(context: Context) -> WKWebView {
8 let webview = WKWebView()
9 return webview
10 }
11
12 func updateUIView(_ uiView: WKWebView, context: Context) {
13 let request = URLRequest(url: url)
14 uiView.load(request)
15 }
16}
17
18struct ContentView: View {
19 var body: some View {
20 WebView(url: URL(string: "https://global-stg.transak.com?apiKey=<YOUR_API_KEY>&sessionId=<YOUR_SESSION_ID>")!)
21 .edgesIgnoringSafeArea(.all)
22 .padding(10)
23 }
24}
3

Create Widget URL (using Backend Only)

Call the Create Widget URL to generate a Widget URL by securely passing the widget parameters.

The response returns a widgetUrl that should be used to load Transak in iOS Webview.

A widgetUrl is valid for 5 minutes and can only be used once. A new widgetUrl must be generated for every user flow.

Example Request:

$curl --request POST \
> --url https://api-gateway-stg.transak.com/api/v2/auth/session \
> --header 'access-token: YOUR_ACCESS_TOKEN' \
> --header 'content-type: application/json' \
> --data '{
> "widgetParams": {
> "apiKey": "YOUR_API_KEY",
> "referrerDomain": "yourdomain.com"
> }
>}'

Use cases

Use the table below to choose the right approach for redirects, order data, and WebView events.

FeatureApproach

How to redirect users back to your app after a transaction

Deeplink

How to get order data (e.g. status, order ID, amount)

Deeplink, Events

Listen to WebView events (order created, widget close, etc.)

Events

Transak supports deeplinking through the use of the redirectURL query parameter to enable seamless navigation after the purchase/sell process is completed.

3

Pass redirectURL in Create Widget URL API

Call the Create Widget URL to generate a Widget URL by securely passing the widget parameters along with the redirectURL parameter.

The response returns a widgetUrl that should be used to load Transak in iOS Webview.

A widgetUrl is valid for 5 minutes and can only be used once. A new widgetUrl must be generated for every user flow.

Example Request:

$curl --request POST \
> --url https://api-gateway-stg.transak.com/api/v2/auth/session \
> --header 'access-token: YOUR_ACCESS_TOKEN' \
> --header 'content-type: application/json' \
> --data '{
> "widgetParams": {
> "apiKey": "YOUR_API_KEY",
> "referrerDomain": "yourdomain.com",
> "redirectURL": "myapp://transak-redirect"
> }
>}'

Events

Transak allows listening of in-widget events (like order creation, completion, and widget close) through native event handlers in iOS WebViews.

Add a script message handler to your WebView using the handler name IosWebview to listen for all frontend events.

1struct WebView: UIViewRepresentable {
2 let url: URL
3
4 func makeCoordinator() -> WebViewCoordinator {
5 return WebViewCoordinator(self)
6 }
7
8 func makeUIView(context: Context) -> WKWebView {
9 let contentController = WKUserContentController()
10 contentController.add(context.coordinator, name: "IosWebview")
11
12 let config = WKWebViewConfiguration()
13 config.userContentController = contentController
14
15 let webView = WKWebView(frame: .zero, configuration: config)
16 webView.navigationDelegate = context.coordinator
17 webView.load(URLRequest(url: url))
18
19 return webView
20 }
21
22 func updateUIView(_ webView: WKWebView, context: Context) {}
23
24 class WebViewCoordinator: NSObject, WKNavigationDelegate, WKScriptMessageHandler {
25 var parent: WebView
26
27 init(_ parent: WebView) {
28 self.parent = parent
29 }
30
31 func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
32 if message.name == "IosWebview", let body = message.body as? String {
33 print(body)
34 }
35 }
36 }
37}

Supported Events

Event NameDescription
TRANSAK_WIDGET_INITIALISED

Widget initialised with query params

TRANSAK_WIDGET_OPEN

Widget fully loaded

TRANSAK_ORDER_CREATED

Order created by user

TRANSAK_ORDER_SUCCESSFUL

Order is successful

TRANSAK_ORDER_CANCELLED

Order is cancelled

TRANSAK_ORDER_FAILED

Order is failed

TRANSAK_WIDGET_CLOSE

Widget is about to close