Web View Controller
Relevant source files
The Web View Controller is the core UI component of LinkSDK that manages the web-based interface for financial account linking and transfer operations. The LinkWebViewViewController class serves as the primary container for web content, JavaScript-to-native communication bridge, and navigation policy enforcement.
For information about the main SDK API classes that create and manage this controller, see LinkSDK and LinkHandler. For details about authentication-specific web components, see Authentication Components.
Architecture Overview
The LinkWebViewViewController acts as a bridge between the native iOS application and web-based content from the Mesh Connect platform. It provides a secure, controlled environment for web content while enabling bidirectional communication through a JavaScript message handler.
Web View Controller Architecture
External Integrations
Security Controls
JavaScript Messages
LinkWebViewViewController
webView
WKWebView
topBar
Native Navigation
jsMessageHandler
JavaScript Bridge
configuration
LinkConfiguration
JSMessageType.brokerageAccountAccessToken
JSMessageType.transferFinished
JSMessageType.showNativeNavbar
JSMessageType.openTrueAuth
JSMessageType.integrationSelected
allowedUrls
External URL List
whitelistedOrigins
Domain Whitelist
decidePolicyFor
Navigation Policy
SFSafariViewController
Safari Integration
TrueAuthWebViewController
Authentication Flow
UIApplication
External App Launch
Sources: LinkSDK/LinkWebViewController/LinkWebViewViewController.swift69-228
JavaScript Message Bridge
The controller implements a sophisticated JavaScript-to-native communication system using WKScriptMessageHandler. This enables the web content to trigger native callbacks and operations.
JavaScript Message Flow
"Host Application""LinkConfiguration""LinkWebViewController""jsMessageHandler""Web Content""Host Application""LinkConfiguration""LinkWebViewController""jsMessageHandler""Web Content"alt[brokerageAccountAccessToken][transferFinished][showNativeNavbar][openTrueAuth][integrationSelected]"JavaScript message""userContentController:didReceive:""Parse JSMessageType""onIntegrationConnected(.accessToken)""Integration callback""onTransferFinished(.success/.error)""Transfer callback""showNativeNavbar(show)""present TrueAuthWebViewController""evaluateJavaScript handleNativeLink"
The supported message types are defined in the JSMessageType enum:
| Message Type | Purpose | Payload Processing |
|---|---|---|
brokerageAccountAccessToken |
Integration completion | Decoded to AccessTokenPayload |
delayedAuthentication |
Delayed auth flow | Decoded to DelayedAuthPayload |
transferFinished |
Transfer operation result | Decoded to success/error payload |
showNativeNavbar |
Navigation bar visibility | Boolean show/hide flag |
integrationSelected |
External app integration | Native link URL handling |
openTrueAuth |
Authentication initiation | Present TrueAuthWebViewController |
loaded |
Page load completion | Inject SDK configuration |
Sources: LinkSDK/LinkWebViewController/LinkWebViewViewController.swift51-62 LinkSDK/LinkWebViewController/LinkWebViewViewController.swift382-463
Navigation Policy System
The controller implements strict navigation policies to ensure security and proper external app integration. The WKNavigationDelegate methods control which URLs can load within the web view versus being opened externally.
URL Routing Decision Tree
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
WeekNavigationAction URL
HTTP/HTTPS scheme?
URL in allowedUrls?
Custom scheme?
Open in Safari
Domain whitelisting disabled?
Load in WebView
Domain in whitelistedOrigins?
UIApplication.canOpenURL?
Cancel navigation
Open in external app
Log unsupported scheme
The security is enforced through two key arrays:
Allowed External URLs (opened in Safari):
https://link.trustwallet.comhttps://appopener.meshconnect.comhttps://www.coinbase.comhttps://api.cb-device-intelligence.com
Whitelisted Domains (loaded in WebView):
.meshconnect.com,.walletconnect.com,.walletconnect.org.okx.com,.gemini.com,.robinhood.com.google.com(for reCAPTCHA),.hcaptcha.com- Various stripe and payment processor domains
Sources: LinkSDK/LinkWebViewController/LinkWebViewViewController.swift19-49 LinkSDK/LinkWebViewController/LinkWebViewViewController.swift310-343
Theme Management
The controller supports dynamic theming based on URL parameters and system appearance. Theme colors are applied to the status bar background and overall interface.
Theme Color Constants
Theme Selection Logic
Dark Theme
Light Theme
dark
light
system
Yes
No
LIGHT_THEME_COLOR_TOP: 0xF3F4F5
LIGHT_THEME_COLOR_BOTTOM: 0xFBFBFB
DARK_THEME_COLOR_TOP: 0x1E1E24
DARK_THEME_COLOR_BOTTOM: 0x0E0D0D
getThemeFromLinkUrl()
Theme Parameter
isDarkTheme = true
isDarkTheme = false
Use traitCollection.userInterfaceStyle
System Dark Mode?
The theme affects:
- Status bar style (
preferredStatusBarStyle) - Background colors for
statusBarBackgroundViewand main view - Navigation button tint colors
Sources: LinkSDK/LinkWebViewController/LinkWebViewViewController.swift14-17 LinkSDK/LinkWebViewController/LinkWebViewViewController.swift198-218
UI Component Structure
The controller uses a structured view hierarchy with Auto Layout constraints to manage the interface layout.
View Hierarchy
Button Configuration
Layout Constraints
topBar height: 68pt
button size: 44x44pt
button margins: 6pt
LinkWebViewViewController.view
statusBarBackgroundView
stackView (UIStackView)
topBar (UIView)
webView (WKWebView)
backButton (UIButton)
closeButton (UIButton)
chevron.left icon
backTapped action
xmark icon
closeTapped action
The native navigation bar (topBar) visibility is controlled dynamically based on:
- JavaScript
showNativeNavbarmessages - Navigation completion events
- URL change detection through KVO on the web view's URL property
Sources: LinkSDK/LinkWebViewController/LinkWebViewViewController.swift78-127 LinkSDK/LinkWebViewController/LinkWebViewViewController.swift260-305 LinkSDK/LinkWebViewController/LinkWebViewViewController.swift246-258
External Integration Capabilities
The controller provides several mechanisms for integrating with external applications and services:
Safari View Controller Integration
For URLs that require external browser access, the controller can present a SFSafariViewController that is automatically dismissed when the app enters the background.
External App Launch
Custom URL schemes (like wallet://) are detected and opened in external applications using UIApplication.shared.open(). The controller checks canOpenURL() before attempting to launch.
TrueAuth Authentication Flow
When receiving an openTrueAuth JavaScript message, the controller presents a dedicated TrueAuthWebViewController for authentication operations, passing an atomic token and result handler.
External Integration Flow
"TrueAuthWebViewController""External App""SFSafariViewController""LinkWebViewController""Web Content""TrueAuthWebViewController""External App""SFSafariViewController""LinkWebViewController""Web Content"alt[Allowed URL][Custom Scheme][TrueAuth Message]"Navigation to external URL""decidePolicyFor navigationAction""Open in Safari""Cancel WebView navigation""UIApplication.shared.open()""Cancel WebView navigation""Present authentication flow""Return result via JavaScript"
Sources: LinkSDK/LinkWebViewController/LinkWebViewViewController.swift449-459 LinkSDK/LinkWebViewController/LinkWebViewViewController.swift329-339 LinkSDK/LinkWebViewController/LinkWebViewViewController.swift151-154