ConnectController

@objcMembers
@MainActor
public class ConnectController : UIViewController, WKNavigationDelegate, WKUIDelegate

A view controller responsible for:

  • Initializing and presenting the WKWebView.
  • Detecting redirects back to the application (via webView(_:decidePolicyFor:decisionHandler:)).
  • Invoking the callback closure when the application redirect is encountered.
  • Opening new-window (target="_blank") links outside the web view.
  • Undocumented

    Declaration

    Swift

    @MainActor
    public var webView: WKWebView!
  • Initializes the ConnectController.

    Declaration

    Swift

    @MainActor
    public init(authUrl: URL,
                redirectUriHost: String?,
                handleCallback: @escaping (URL) -> Void,
                onCompleteResult: @escaping (CompleteParams) -> Void = { _ in })

    Parameters

    authUrl

    The Connect URL to open in the WKWebView.

    redirectUriHost

    Host of the redirect URI that was passed to SmartcarAuth. nil when the flow was configured without a redirect URI (responseType == "none").

    handleCallback

    Callback function that is invoked upon redirect back to the application.

    onCompleteResult

    Callback function that is invoked when Connect signals flow completion via the complete RPC instead of a redirect.

  • Undocumented

    Declaration

    Swift

    @MainActor
    public override func viewDidLoad()
  • WKNavigationDelegate method: listens for navigation changes. If the navigation is to the redirect URI (matching redirectUriHost), call the handleCallback and remove the webView from the view. If the navigation is a new-window request (target="_blank"), open it externally and leave the Connect page in place.

    Declaration

    Swift

    @MainActor
    public func webView(_ webView: WKWebView,
                        decidePolicyFor navigationAction: WKNavigationAction,
                        decisionHandler: @escaping (WKNavigationActionPolicy) -> Void)
  • WKUIDelegate method: called when the page asks for a new window that didn’t go through decidePolicyFor first (e.g. a user-initiated window.open()). There’s no second screen to show it in, so open the URL externally and decline to create a web view.

    Declaration

    Swift

    @MainActor
    public func webView(_ webView: WKWebView,
                        createWebViewWith configuration: WKWebViewConfiguration,
                        for navigationAction: WKNavigationAction,
                        windowFeatures: WKWindowFeatures) -> WKWebView?
  • Undocumented

    Declaration

    Swift

    @MainActor
    public override func viewDidDisappear(_ animated: Bool)