Skip to content
Release: Australia · Updated: 2026-03-12 · Official documentation · View source

NowWebService class- iOS

The NowWebService class provides functions that enable the browsing of web pages on a ServiceNow instance.

Image omitted: mobsdk-web-start-flow.png
Web page load flow
NameTypeDescription
configurationNowServiceConfigurationConfiguration parameters to use when initializing the NowWebService instance.

Parent Topic:Mobile SDK - iOS

NowWebService - init(configuration: NowServiceConfiguration, coreServiceProvider: NowCoreServiceProviding? = nil)

Initializes a NowWebService instance.

NameTypeDescription
configurationNowServiceConfigurationConfiguration parameters to use when initializing the NowWebService instance.
coreServiceProviderNowCoreServiceProvidingOptional. Service provider to associate with the NowWebService instance.Default: nil

The following code example shows how to call this method.

guard let coreService = NowSDK.core() else {
  // Error with NowServiceError.sdkNotConfigured
  return
}
guard 
  let instanceUrl = URL(string: "http://sample.service-now.com") , 
  let serviceConfig = NowSDK.makeServiceConfiguration(for: instanceUrl) else {
    // Could not create service – 
    // NowServiceError.serviceConfigurationInvalid
    return
}

let webService = NowWebService(configuration: serviceConfig, coreServiceProvider: coreService)

NowWebService - makeWebViewController(for url: URL, delegate: NowWebViewControllerDelegate, theme: NowWebThemeable)

Creates a UIViewController object that hosts the web view.

NameTypeDescription
for urlURLURL of the web page to load. This web page must be on the target ServiceNow instance that the service was initialized with.
delegateNowWebViewControllerDelegateOptional. Object that receives callback events from the WebViewController into the native application.
themeNowWebThemeable protocol - iOSOptional. NowUIThemeable protocol to apply to the UI elements of the view controller, such as color.Default: NowWebDefaultTheme\(nowUITheme: NowUIDefaultTheme\(\)\)
TypeDescription
Result<NowWebViewController, NowWebServiceError>Success: NowWebViewController objectFailure: NowWebServiceError object
private func webViewController(for url: URL) -> NowWebViewController? {
  guard let webService = webService else {
    debugPrint("Web service not initialized")
    return nil
  }

  let result = webService.makeWebViewController(for: url, delegate: self, theme: CarrascoWebTheme(nowUITheme: CarrascoTheme()))
  switch result {
    case .success(let viewController):
      return viewController
    case .failure(let error):
      debugPrint("Web view creation failed with error: \(error.localizedDescription)")
  }
  return nil
}

NowWebService - preloadWebCache(urls: [URL], completion: PreloadWebCacheCompletion? = nil) throws

Preloads a list of specified pages with cacheable resources in the background (by NowWeb) to improve initial load times.

NameTypeDescription
urlsArray of URL objectsURLs of the pages to preload.
completionPreloadWebCacheCompletionOptional. Closure to inform the caller that the web pages have completed loading.
TypeDescription
None 

The following example shows how to use the webService.preloadWebCache() function to pre-load specified pages.

private func preloadURLs(urls: [URL]) {
  guard let webService = webService else {
    debugPrint("Web service not initialized")
    return
  }
  do {
       try webService.preloadWebCache(urls: urls) {
         debugPrint("URLs did complete preloading")
       }

  } catch {
      debugPrint(error.localizedDescription)
  }
}