---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# NowWebService class - iOS

# NowWebService class - iOS {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 minute to read

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

| Name | Type | Description |
|-|-|-|
| configuration | [NowServiceConfiguration](https://servicenow-prod.fluidtopics.net/A6W2zQ0fOO_VQ9lbo3VKwQ#NowServiceConfigurationiOSStruct "The NowServiceConfiguration structure defines configuration information for a feature service.") | Configuration parameters to use when initializing the NowWebService instance. |
[Table 1. Properties]

{#NowWebServiceiOSAPI__table_vx2_klw_5pb}

## NowWebService - init(configuration: NowServiceConfiguration, coreServiceProvider:
NowCoreServiceProviding? = nil) {#ariaid-title2}

Initializes a NowWebService instance.
{#NWebServ-init_O_S__table_lc2_n13_ppb__entry__3}

| Name | Type | Description |
|-|-|-|
| configuration | [NowServiceConfiguration](https://servicenow-prod.fluidtopics.net/A6W2zQ0fOO_VQ9lbo3VKwQ#NowServiceConfigurationiOSStruct "The NowServiceConfiguration structure defines configuration information for a feature service.") | Configuration parameters to use when initializing the NowWebService instance. |
| coreServiceProvider | NowCoreServiceProviding | Optional. Service provider to associate with the NowWebService instance. Default: nil |
[Table 2. Parameters]

{#NWebServ-init_O_S__table_lc2_n13_ppb}  
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) {#ariaid-title3}

Creates a UIViewController object that hosts the web view.
{#NWebServ-makeWebViewCont_S_S_O__table_pnt_hb3_ppb__entry__3}

| Name | Type | Description |
|-|-|-|
| for url | URL | URL of the web page to load. This web page must be on the target ServiceNow instance that the service was initialized with. |
| delegate | NowWebViewControllerDelegate | Optional. Object that receives callback events from the WebViewController into the native application. |
| theme | NowWebThemeable | Optional. NowUIThemeable protocol to apply to the UI elements of the view controller, such as color. Default: NowWebDefaultTheme(nowUITheme: NowUIDefaultTheme()) |
[Table 3. Parameters]

{#NWebServ-makeWebViewCont_S_S_O__table_pnt_hb3_ppb} {#NWebServ-makeWebViewCont_S_S_O__table_qnt_hb3_ppb__entry__2}

| Type | Description |
|-|-|
| Result\<NowWebViewController, NowWebServiceError\> | Success: NowWebViewController object Failure: NowWebServiceError object |
[Table 4. Returns]

{#NWebServ-makeWebViewCont_S_S_O__table_qnt_hb3_ppb}  
<br />

    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 {#ariaid-title4}

Preloads a list of specified pages with cacheable resources in the background (by NowWeb) to improve initial load times.
{#NWebServ-preloadWebCache_A_S__table_jfm_zbs_gyb__entry__3}

| Name | Type | Description |
|-|-|-|
| urls | Array of URL objects | URLs of the pages to preload. |
| completion | PreloadWebCacheCompletion | Optional. Closure to inform the caller that the web pages have completed loading. |
[Table 5. Parameters]

{#NWebServ-preloadWebCache_A_S__table_jfm_zbs_gyb} {#NWebServ-preloadWebCache_A_S__table_kfm_zbs_gyb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 6. Returns]

{#NWebServ-preloadWebCache_A_S__table_kfm_zbs_gyb}  
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)
      }
    }


