WebViewPresenter

WebViewPresenter


Web views are required by some authentication steps, as they need to present a login form for user authentication.

This SDK supports four web view types:

  • UIWebView
  • WKWebView
  • SFSafariViewController
  • SFAuthenticationSession

There are presenter protocols for each supported web view type:

  • UIWebViewPresenting
  • WKWebViewPresenting
  • SFSafariViewControllerPresenting
  • SFAuthenticationSessionPresenting
  • ASWebAuthenticationSessionPresenting

And one default implementation for each:

  • UIWebViewPresenter
  • WKWebViewPresenter
  • SFSafariViewControllerPresenter
  • SFAuthenticationSessionPresenter

Usage

Usage scenario 1: Pass presenter to SDK components

  1. Create an instance of one of the default presenters (or implement your own).
  2. Set it as webViewPresenter for authenticator components.

The following listing is an example of how to use this component in combination with UIWebViewPresenter which is one of the provided default implementations:

let authenticatorParams = SAMLAuthenticationParameters(authorizationEndpointURL: URL(string:<##>)!, finishEndpointURL: URL(string:<##>)!)
let authenticator = SAMLAuthenticator(using: authenticatorParams)
authenticator.webViewPresenter = UIWebViewPresenter()

The example above assumes you have an SAMLAuthenticator component that you want to use with your own presenter.

Usage scenario 2: Use presenter directly in your app

  1. Create an instance of one of the default presenters (or implement your own).
  2. Use it for your own purposes.
  3. Call dismissWebView() once you finish.
let presenter = UIWebViewPresenter()

presenter.presentWebView { webView, error in
    if let error = error {
        // error handling
        return
    }

    uiWebView.load(request: request)

    // Dismiss the web view when you don't need it anymore
    presenter.dismissWebView()
}

Notes:

You must call the present and dismiss method of the presenter on the main thread!

View hierarchy

By default, the default web view presenters present the web view on top of the top-most UIViewController. You can change this by setting the webViewPresentingViewController property (on the default presenters) to your own UIViewController. For example:

let uiWebViewPresenter = UIWebViewPresenter()
uiWebViewPresenter.webViewPresentingViewController = <preseing UIViewController of your choice>

Custom implementation

You can define your own implementation of the presenter:

  1. Implement one of the supported web view presenter protocols.
  2. Supply one of the system web views in the presentWebView’s completionHandler.

You must call the completionHandler on the main thread!

  • This protocol represents a delegate which can be called by one of the web view presenting implementation.

    See more

    Declaration

    Swift

    public protocol WebViewPresenterDelegate : AnyObject
  • This protocol represents an API which is capable of presenting a ASWebAuthenticationSession.

    See more

    Declaration

    Swift

    @available(iOS 12.0, *)
    public protocol ASWebAuthenticationSessionPresenting : AnyObject
  • This protocol represents an API which is capable of presenting a SFAuthenticationSession.

    See more

    Declaration

    Swift

    @available(*, deprecated, message: "Use ASWebAuthenticationSessionPresenting instead")
    public protocol SFAuthenticationSessionPresenting : AnyObject
  • This protocol represents an API which is capable of presenting a SFSafariViewController.

    See more

    Declaration

    Swift

    public protocol SFSafariViewControllerPresenting : AnyObject
  • This protocol represents an API which is capable of presenting an UIWebView.

    See more

    Declaration

    Swift

    @available(*, deprecated, message: "Use WKWebViewPresenting instead")
    public protocol UIWebViewPresenting : AnyObject
  • This protocol represents an API which is capable of presenting a WKWebView.

    See more

    Declaration

    Swift

    public protocol WKWebViewPresenting : AnyObject
  • This protocol extends the UIWebViewDelegate with SAP specific functionality.

    See more

    Declaration

    Swift

    @available(*, deprecated, message: "Use SAPWKNavigationDelegate instead")
    public protocol SAPUIWebViewDelegate : AnyObject
  • This protocol extends the WKNavigationDelegate with SAP specific functionality.

    See more

    Declaration

    Swift

    public protocol SAPWKNavigationDelegate : AnyObject