iOS WebView Integration

Introduction

TrustX is not only supported in browser flows but also allows for integration through WebView objects such that users can implement the TrustX flow directly through their native applications. This document will cover the integration requirements for iOS devices.

WKWebView Configuration

The iOS WKWebView is a standard framework component located in the WebKit framework. For more details, please refer to Apple's developer documentation.

Initial WKWebView integration

This code snipped represents a basic WKWebView integration in any app:

Swift
Copy

After the initial integration of the WKWebView through StoryBoard or code, additional configurations are required.

Camera Permissions

To add a camera usage description to the application, add NSCameraUsageDescription to the application 'info.plist' file. This is a message that informs the end-user why the app is requesting access to the device's camera. More info: https://developer.apple.com/documentation/bundleresources/information_property_list/nscamerausagedescription

To follow the camera permission settings of the application, implement the WKUIDelegate method. This feature is available starting from iOS 15; before that version, users will need to use prompts from the web application.

Code sample:

Swift
Copy

For more information, see webView(_:requestMediaCapturePermissionFor:initiatedByFrame:type:decisionHandler:)

WKScriptMessageHandler

To listen for any web event from TrustX, utilize the WKScriptMessageHandler. The userContentController(_:didReceive:)method can be used to inform the handler that a webpage has sent a script message.

Swift
Copy

For more information, see userContentController(_:didReceive:)

The following table details all event that can be received from TrustX. The returned value from the listed events will be the event name.

Event NameDescription
webLoadedA safety feature to ensure that only the TrustX web app can be loaded.
webCompletedindicates the completion of the TrustX flow.
webTimeoutIndicates that an activity has expired during the TrustX flow.
openCameraSettingsUsed to notify the iOS app that the WebApp is requesting to open the application settings.
errorIndicates an error has occurred.

For example:

Swift
Copy

WKWebViewConfiguration

After configuring the web view as desired, additional configurations must be made to ensure that the TrustX flow works as intended.

First, set the allowsInlineMediaPlayback to true which will enable inline media playback.

Swift
Copy

For more information, see allowsInlineMediaPlayback

To receive events inside the userContentController function, it's necessary to subscribe to each event using add(_:name:) function.

Swift
Copy

For more information, see add(_:name:)

Below is an example of setting the allowsInlineMediaPlayback configuration.

Swift
Copy

Web App Navigation

In some cases of the TrustX flow, navigation is required to be implemented in the native UI. After adding a button to the UI, an action should be assigned to the button. For example, the goBack() function can be assigned to return to the 'back' item in the back-forward list.

For example:

Swift
Copy

For more information on this function, see goBack().

Example of Full WebView Component Configuration

Below is a code example showing how to initialise, configure and load URL into WebView component using the above implementations:

Swift
Copy

Known Issues and Limitations

WebRTC, one of the main component of TrustX, does not support camera functionality in WKWebView on iOS versions earlier than 14.3.

Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard