NowWebViewControllerDelegate protocol - iOS

  • Release version: Zurich
  • Updated July 31, 2025
  • 2 minutes to read
  • The NowWebViewControllerDelegate protocol provides callbacks for notification of issues within the NowWebViewController processing such as when a flow ends or a navigation fails.

    NowWebViewControllerDelegate - nowWebViewController(_ nowWebViewController: NowWebViewController, didEndFlow flowName: String)

    Callback that notifies the host application that the specified Cabrillo (mobile web) flow has ended.

    Table 1. Parameters
    Name Type Description
    nowWebViewController NowWebViewController Instance of NowWebViewController where the flow ended.
    didEndFlow flowName String Name of the Cabrillo flow that ended
    Table 2. Returns
    Type Description
    None

    The following code example shows how to call this method.

    func nowWebViewController(_ nowWebViewController: NowWebViewController, didEndFlow flowName: String) {
      debugPrint("ended flow named: \(flowName)")
    }

    NowWebViewControllerDelegate - nowWebViewController(_ nowWebViewController: NowWebViewController, didFailNavigationWith error: Swift.Error)

    Callback that notifies the host application that the web view navigation has failed.

    Table 3. Parameters
    Name Type Description
    nowWebViewController NowWebViewController Instance of NowWebViewController in which the navigation failed.
    didFailNavigationWith error Swift.Error Error raised from the navigation failure.
    Table 4. Returns
    Type Description
    None

    The following code example shows how to call this method.

    func nowWebViewController(_ nowWebViewController: NowWebViewController, didFailNavigationWith error: Error) {
      debugPrint("NowWebViewController encountered a navigation error: \(error.localizedDescription)")
    }

    NowWebViewControllerDelegate - nowWebViewController(_ nowWebViewController: NowWebViewController, didReceive unsupportedUrl: URL)

    Callback that notifies the host application that the web view attempted to load an unsupported URL.

    An unsupported URL could be one for a different ServiceNow instance or an absolute URL with an invalid scheme.
    Note:
    Valid schemes are http and https.
    Table 5. Parameters
    Name Type Description
    nowWebViewController NowWebViewController Instance of NowWebViewController used when attempting to load the unsupported URL.
    didReceive unsupportedUrl URL Invalid URL trying to be loaded.
    Table 6. Returns
    Type Description
    None

    The following code example shows how to call this method.

    func nowWebViewController(_ nowWebViewController: NowWebViewController, didReceive unsupportedUrl: URL) {
      debugPrint("nowWebViewController:receivedUnsupportedUrl: \(unsupportedUrl.absoluteString)")
    }

    NowWebViewControllerDelegate - nowWebViewControllerDidRequestDismissal(_ nowWebViewController: NowWebViewController)

    Callback that notifies the host application that during a back navigation attempt, the stack was exhausted. The host application can then decide whether to dismiss the NowWebViewController instance.

    Table 7. Parameters
    Name Type Description
    nowWebViewController NowWebViewController Instance of NowWebViewController in which the back navigation was attempted.
    Table 8. Returns
    Type Description
    None

    The following code example shows how to call this method.

    func nowWebViewControllerDidRequestDismissal(_ nowWebViewController: NowWebViewController) {
      navigationController?.popViewController(animated: true)
    }

    NowWebViewControllerDelegate - nowWebViewController(_ nowWebViewController: NowWebViewController, systemThemeDidChange traitCollection: UITraitCollection)

    Callback that notifies the host application that the system web UI theme changed.

    Table 9. Parameters
    Name Type Description
    nowWebViewController NowWebViewController Instance of NowWebViewController in which the web UI theme changed.
    traitCollection UITraitCollection UITraitCollection object that contains the new theme.
    Table 10. Returns
    Type Description
    None

    The following code example shows how to override the systemThemeDidChange() delegate function to call the updateTheme() function to apply theme changes when the system theme changes.

    func nowWebViewController(_ nowWebViewController: NowWebViewController, systemThemeDidChange traitCollection: UITraitCollection) {
    
      /// Called when the system changes between dark and light mode
    
        /// You can call the corresponding updateTheme() method here to change the UI theme based on System Theme
        nowWebViewController.updateTheme(themeColors: traitCollection.userInterfaceStyle == .dark ? DarkNowWebTheme() : LightNowWebTheme())
          print(“System Theme Did Change)
    }