> ## Documentation Index
> Fetch the complete documentation index at: https://docs.subtotal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Link accounts in your iOS App

> Learn how to launch Subtotal Link in your iOS application

## Overview

We'll use [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview) to add [Subtotal Link](https://wwww.subtotal.com/docs/subtotal-link) into your iOS application.

## Create a view with a button

Add a button that to launch Subtotal Link in a WebView. The WebView handles the entire account linking process.

```swift theme={null}
struct ContentView: View {
    @State private var showWebView = false
    
    var body: some View {
        NavigationStack {
            Button("Link your account") {
                showWebView = true
            }
            .navigationDestination(isPresented: $showWebView) {
                SubtotalLinkView()
            }
        }
    }
}
```

## Launch Subtotal Link in a WKWebView

Create a WKWebView to display Subtotal Link. The [WKWebViewConfiguration](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration) shown below is required for Subtotal Link to work properly.

```swift theme={null}
import SwiftUI
import WebKit

struct SubtotalLinkView: View {
    var body: some View {
        SubtotalWebView()
    }
}

struct SubtotalWebView: UIViewRepresentable {
    func makeUIView(context: Context) -> WKWebView {
        let webConfiguration = WKWebViewConfiguration()
        webConfiguration.allowsInlineMediaPlayback = true
        webConfiguration.applicationNameForUserAgent = "Subtotal Custom WebView User Agent"
        
        let webView = WKWebView(frame: .zero, configuration: webConfiguration)
        
        // Copy and paste a Link URL from the Subtotal Dashboard
        let linkURL = "https://link.subtotal.com/tWGE4TJM"
        if let url = URL(string: linkURL) {
            webView.load(URLRequest(url: url))
        }
        
        return webView
    }
    
    func updateUIView(_ webView: WKWebView, context: Context) {
        // Required by UIViewRepresentable protocol - URL is already loaded in makeUIView
    }
}
```

**Note:** To handle the `redirect_url` when users complete or exit linking, add a `Coordinator` with `WKNavigationDelegate` and implement `webView(_:decidePolicyFor:decisionHandler:)` to detect your URL scheme and dismiss the WebView.

## That's It!

Your iOS app now is now using Subtotal Link to link retail accounts.
