---
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


---

# NowCoreService class - iOS

# NowCoreService class - iOS {#ariaid-title1}

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

The NowCoreService class provides fundamental services to the
various SDK feature services. This class should only be instantiated by NowSDK.

Feature services, such as Now Analytics and NowChat, can access a shared core instance
through the NowSDK.core property.

## NowCoreService - accessTokenDidFail(for service: NowService) {#ariaid-title2}

Notifies the SDK core that the access token used to authorize the API requests to the ServiceNow instance for the specified service is no longer valid.
The SDK core returns a valid access token if it is able to generate one or returns an
error.  
Note:  
This method has been deprecated. You should use the async/await implementation of the method instead.
{#NCoreServ-accessTokenDidFail_O__table_p5n_vcb_npb__entry__3}

| Name | Type | Description |
|-|-|-|
| for service | [NowService](https://servicenow-prod.fluidtopics.net/_vkGd0wUgkXdLiQytHy27A#NowServiceiOSProtocol "The NowService protocol provides a single interface to the NowSDK for all feature services. It defines the configuration parameters needed to access your ServiceNow instance.") | Feature service requesting the access token. |
[Table 1. Parameters]

{#NCoreServ-accessTokenDidFail_O__table_p5n_vcb_npb} {#NCoreServ-accessTokenDidFail_O__table_q5n_vcb_npb__entry__2}

| Type | Description |
|-|-|
| AnyPublisher\<NowSDK.AccessToken, AccessTokenProviderError\> | Success: Valid access token. Failure: AccessTokenProviderError Possible values: * userSessionError * accessTokenRetrievalFailed * hostReturnedNoTokens - Indicates a guest user |
[Table 2. Returns]

{#NCoreServ-accessTokenDidFail_O__table_q5n_vcb_npb}  
<br />

    NowSDK.core()?.accessTokenDidFail(for: someService)
      .mapError { YourCustomError.accessTokenFailed($0) }

    .flatMap(self.handleFailedAccessToken())
      .eraseToAnyPublisher()

## NowCoreService - accessTokenDidFail(for service: NowService) async throws {#ariaid-title3}

Notifies the SDK core that the access token used to authorize the API requests to the ServiceNow instance for the specified service is no longer valid.
The SDK core returns a valid access token if it is able to generate one or returns an error.
{#NCoreServ-accessTokDidFail-async_O__table_p5n_vcb_npb__entry__3}

| Name | Type | Description |
|-|-|-|
| for service | [NowService](https://servicenow-prod.fluidtopics.net/_vkGd0wUgkXdLiQytHy27A#NowServiceiOSProtocol "The NowService protocol provides a single interface to the NowSDK for all feature services. It defines the configuration parameters needed to access your ServiceNow instance.") | Feature service requesting the access token. |
[Table 3. Parameters]

{#NCoreServ-accessTokDidFail-async_O__table_p5n_vcb_npb} {#NCoreServ-accessTokDidFail-async_O__table_q5n_vcb_npb__entry__2}

| Type | Description |
|-|-|
| NowSDK.AccessToken | Returned when the method is successful. Valid access token. |
| AccessTokenProviderError | Thrown when the method fails. Indicates an error retrieving an access token. Possible values: * userSessionError * accessTokenRetrievalFailed * hostReturnedNoTokens - Indicates a guest user |
[Table 4. Returns]

{#NCoreServ-accessTokDidFail-async_O__table_q5n_vcb_npb}  
The following code examples shows how to call this method.

    do {
        let accessToken = try await NowSDK.core()?.accessTokenDidFail(for: someService)
    } catch {
        self.handleFailedAccessToken(error)
    }

## NowCoreService - canRequestPermission(_ permission: DevicePermission) {#ariaid-title4}

Queries the host application as to whether the service is allowed to request the device
permission.
This function does not request the permission, only whether it is allowed to query the
device permission. Feature services should call this function to determine if they are
allowed to request a desired device permission.
{#NCoreServ-canReqPermission_S__table_t4p_c1b_npb__entry__3}

| Name | Type | Description |
|-|-|-|
| permission | DevicePermission | Device for which the request is being made. Possible values (case-sensitive): * camera * location * microphone * photoLibrary * speachRecognition |
[Table 5. Parameters]

{#NCoreServ-canReqPermission_S__table_t4p_c1b_npb} {#NCoreServ-canReqPermission_S__table_u4p_c1b_npb__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the host application allows the SDK to request the specified device permission. Possible values: * true: Device permission can be requested. * false: Device permission cannot be requested. |
[Table 6. Returns]

{#NCoreServ-canReqPermission_S__table_u4p_c1b_npb}  
<br />

    extension AppDelegate: DevicePermissionDelegate {
      func canRequestPermission(_ permission: DevicePermission) -> Bool {
        return true
      }
    }

## NowCoreService - isGuestUser(for service: NowService) async {#ariaid-title5}

Checks whether the current user is a guest user.
{#NCoreServ-isGuestUser-async_O__table_ugj_4w2_lxb__entry__3}

| Name | Type | Description |
|-|-|-|
| for service | NowService | Feature service for which to perform the guest user check. |
[Table 7. Parameters]

{#NCoreServ-isGuestUser-async_O__table_ugj_4w2_lxb} {#NCoreServ-isGuestUser-async_O__table_vgj_4w2_lxb__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the current user is a guest user. Possible values: * true: Current user of the specified service is a guest user. * false: Current user of the specified service is not a guest user. |
[Table 8. Returns]

{#NCoreServ-isGuestUser-async_O__table_vgj_4w2_lxb}  
The following code example shows how to call this method.

    let isGuestUser = await NowSDK.core()?.isGuestUser(for: someService)

## NowCoreService - refreshAllSettings() {#ariaid-title6}

Refreshes all SDK settings for all services by re-fetching them from the active
servers.
To receive updated SDK settings values whenever they're refreshed, subscribe to the publisher provided by the [NowCoreService - settingsPublisher(for service: NowService)](https://servicenow-prod.fluidtopics.net/Y~IevmLBZx4fxGcoEd~5tQ#NCoreServ-settingsPublisher_O "Retrieves the settings for the publisher of the specified service.") function.
{#NCoreServ-refreshAllSettings__table_ckb_zgb_npb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 9. Parameters]

{#NCoreServ-refreshAllSettings__table_ckb_zgb_npb} {#NCoreServ-refreshAllSettings__table_dkb_zgb_npb__entry__2}

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

{#NCoreServ-refreshAllSettings__table_dkb_zgb_npb}  
<br />

    NowSDK.core()?.refreshAllSettings()

## NowCoreService - refreshSettings(for service: NowService) {#ariaid-title7}

Refreshes the SDK settings for the specified service by re-fetching them from the
server.
Note:  
This method has been deprecated. You should use the async/await implementation of the method instead.
{#NCoreServ-refreshSettings_S__table_qv3_knb_npb__entry__3}

| Name | Type | Description |
|-|-|-|
| for service | NowService | Feature service, such as NowChat or NowAnalytics, requesting the settings refresh. |
[Table 11. Parameters]

{#NCoreServ-refreshSettings_S__table_qv3_knb_npb} {#NCoreServ-refreshSettings_S__table_rv3_knb_npb__entry__2}

| Type | Description |
|-|-|
| AnyPublisher\<Settings, SettingsError\> | Success: Dictionary of refreshed SDK settings. Feature services need to examine the returned data for the settings relevant to their specific features. Failure: SettingsError - Type and description of error encountered. Possible values: * fetchError * fetchFailed * invalidJSON * invalidProvider * notAuthorized * sdkNotLicensed * settingNotFound * unknown |
[Table 12. Returns]

{#NCoreServ-refreshSettings_S__table_rv3_knb_npb}  
<br />

    var subscriptions = Set<AnyCancellable>()
    NowSDK.core?.refreshSettings(for: someService)
      .sink(receiveCompletion: { completion in
        if case .failure(let error) = completion {
          print("Refresh failed with error:\ (error)")
        }
      }, receiveValue: { settings in
        print("Received refreshed settings:\ (settings)")
      })
      .store(in: &subscriptions)

## NowCoreService - refreshSettings(for service: NowService) async throws {#ariaid-title8}

Refreshes the SDK settings for the specified service by re-fetching them from the server.
{#NCoreServ-refreshSettings-async_S__table_qv3_knb_npb__entry__3}

| Name | Type | Description |
|-|-|-|
| for service | NowService | Feature service, such as NowChat or NowAnalytics, requesting the settings refresh. |
[Table 13. Parameters]

{#NCoreServ-refreshSettings-async_S__table_qv3_knb_npb} {#NCoreServ-refreshSettings-async_S__table_rv3_knb_npb__entry__2}

| Type | Description |
|-|-|
| Settings | Returned when the method is successful. Dictionary of refreshed SDK settings. Feature services need to examine the returned data for the settings relevant to their specific features. |
| SettingsError | Thrown when the method fails. Possible values: * fetchError * fetchFailed * invalidJSON * invalidProvider * notAuthorized * sdkNotLicensed * settingNotFound * unknown |
[Table 14. Returns]

{#NCoreServ-refreshSettings-async_S__table_rv3_knb_npb}  
The following code examples shows how to call this method.

    do {
        let settings = try await NowSDK.core()?.refreshSettings(for: someService)
        print("Received refreshed settings: \(settings)")
    } catch {
        print("Refresh failed with Settings error: \(error)")
    }

## NowCoreService - requestAccessToken(for service: NowService) {#ariaid-title9}

Acquires an access token for the specified service.
Note:  
This method has been deprecated. You should use the async/await implementation of the method instead.
{#NCoreServ-requestAccessToken_O__table_dt1_ftb_npb__entry__3}

| Name | Type | Description |
|-|-|-|
| for service | [NowService](https://servicenow-prod.fluidtopics.net/_vkGd0wUgkXdLiQytHy27A#NowServiceiOSProtocol "The NowService protocol provides a single interface to the NowSDK for all feature services. It defines the configuration parameters needed to access your ServiceNow instance.") | Feature service requesting the access token. |
[Table 15. Parameters]

{#NCoreServ-requestAccessToken_O__table_dt1_ftb_npb} {#NCoreServ-requestAccessToken_O__table_et1_ftb_npb__entry__2}

| Type | Description |
|-|-|
| AnyPublisher\<NowSDK.AccessToken, AccessTokenProviderError\> | Success: NowSDK.AccessToken - Access token to use to authorize API requests made to a ServiceNow instance. Failure: AccessTokenProviderError - Type and description of error encountered. Possible values: * accessTokenRetrievalFailed * hostReturnedNoTokens - Indicates a guest user * userSessionError |
[Table 16. Returns]

{#NCoreServ-requestAccessToken_O__table_et1_ftb_npb}  
<br />

    NowSDK.core()?.requestAccessToken(for: someService)

## NowCoreService - requestAccessToken(for service: NowService) async throws {#ariaid-title10}

Acquires an access token for the specified service.
{#NCoreServ-requestAccessToken-async_O__table_dt1_ftb_npb__entry__3}

| Name | Type | Description |
|-|-|-|
| for service | [NowService](https://servicenow-prod.fluidtopics.net/_vkGd0wUgkXdLiQytHy27A#NowServiceiOSProtocol "The NowService protocol provides a single interface to the NowSDK for all feature services. It defines the configuration parameters needed to access your ServiceNow instance.") | Feature service requesting the access token. |
[Table 17. Parameters]

{#NCoreServ-requestAccessToken-async_O__table_dt1_ftb_npb} {#NCoreServ-requestAccessToken-async_O__table_et1_ftb_npb__entry__2}

| Type | Description |
|-|-|
| NowSDK.AccessToken | Returned when the method is successful. Access token to use to authorize API requests made to a ServiceNow instance. |
| AccessTokenProviderError | Thrown when the method fails. Indicates an error retrieving an access token. Possible values: * accessTokenRetrievalFailed * hostReturnedNoTokens - Indicates a guest user * userSessionError |
[Table 18. Returns]

{#NCoreServ-requestAccessToken-async_O__table_et1_ftb_npb}  
The following code examples shows how to call this method.

    do {
        let accessToken = try await NowSDK.core()?.requestAccessToken(for: someService)
    } catch {
        self.handleFailedAccessToken(error)
    }

## NowCoreService - requestNetworkService(for service: NowService) {#ariaid-title11}

Returns a reference to a shared network service that you can use to make API
requests.
Note:  
This is a shared service. Altering settings or ending the session can cause issues for other feature services that share this session.
{#NCoreServ-reqNetworkService_O__table_zmb_tpb_npb__entry__3}

| Name | Type | Description |
|-|-|-|
| for service | [NowService](https://servicenow-prod.fluidtopics.net/_vkGd0wUgkXdLiQytHy27A#NowServiceiOSProtocol "The NowService protocol provides a single interface to the NowSDK for all feature services. It defines the configuration parameters needed to access your ServiceNow instance.") | Feature service requesting the network service. |
[Table 19. Parameters]

{#NCoreServ-reqNetworkService_O__table_zmb_tpb_npb} {#NCoreServ-reqNetworkService_O__table_dkb_zgb_npb__entry__2}

| Type | Description |
|-|-|
| NetworkService | Shared network service that you can use to make API calls. |
[Table 20. Returns]

{#NCoreServ-reqNetworkService_O__table_dkb_zgb_npb}  
The following code example shows how to call this function.

    NowSDK.core()?.settingsPublisher(for: chatService)
    .sink(receiveCompletion: { completion in
      if case .failure(let error) = completion {
        // Setting publisher failed with error
      }
    }, receiveValue: { updatedSettings in
      // Receive array of SDK settings for chatService
    })
    .store(in: &subscriptions)

## NowCoreService - requestSettings(forservice: NowService) {#ariaid-title12}

Returns the SDK settings for the specified feature service.
Note:  
This method has been deprecated. You should use the async/await implementation of the method instead.
{#NCoreServ-requestSettings_O__table_qwv_s5b_npb__entry__3}

| Name | Type | Description |
|-|-|-|
| forservice | NowService | Feature service requesting the settings. |
[Table 21. Parameters]

{#NCoreServ-requestSettings_O__table_qwv_s5b_npb} {#NCoreServ-requestSettings_O__table_rwv_s5b_npb__entry__2}

| Type | Description |
|-|-|
| AnyPublisher\<Settings, SettingsError\> | Success: Settings - Array of SDK settings for the specified feature service. Failure: SettingsError - Type and description of associated error. Possible values: * fetchError * fetchFailed * invalidJSON * invalidProvider * notAuthorized * sdkNotLicensed * settingNotFound * unknown |
[Table 22. Returns]

{#NCoreServ-requestSettings_O__table_rwv_s5b_npb}  
<br />

    NowSDK.core()?.requestSettings(for: someService)

## NowCoreService - requestSettings(for service: NowService) async throws {#ariaid-title13}

Returns the SDK settings for the specified feature service.
{#NCoreServ-requestSettings-async_O__table_qwv_s5b_npb__entry__3}

| Name | Type | Description |
|-|-|-|
| for service | NowService | Feature service requesting the settings. |
[Table 23. Parameters]

{#NCoreServ-requestSettings-async_O__table_qwv_s5b_npb} {#NCoreServ-requestSettings-async_O__table_rwv_s5b_npb__entry__2}

| Type | Description |
|-|-|
| Settings | Returned when the method is successful. Array of SDK settings for the specified feature service. |
| SettingsError | Thrown when the method fails. Type and description of associated error. Possible values: * fetchError * fetchFailed * invalidJSON * invalidProvider * notAuthorized * sdkNotLicensed * settingNotFound * unknown |
[Table 24. Returns]

{#NCoreServ-requestSettings-async_O__table_rwv_s5b_npb}  
The following code examples shows how to call this method.

    do {
        let settings = try await NowSDK.core()?.requestSettings(for: someService)
        print("Received settings: \(settings)")
    } catch {
        print("Refresh saved with Settings error: \(error)")
    }

## NowCoreService - settingsPublisher(for service: NowService) {#ariaid-title14}

Retrieves the settings for the publisher of the specified service.
{#NCoreServ-settingsPublisher_O__table_jbw_j1c_npb__entry__3}

| Name | Type | Description |
|-|-|-|
| for service | [NowService protocol - iOS](https://servicenow-prod.fluidtopics.net/_vkGd0wUgkXdLiQytHy27A#NowServiceiOSProtocol "The NowService protocol provides a single interface to the NowSDK for all feature services. It defines the configuration parameters needed to access your ServiceNow instance.") | Feature service requesting the publisher subscription. |
[Table 25. Parameters]

{#NCoreServ-settingsPublisher_O__table_jbw_j1c_npb} {#NCoreServ-settingsPublisher_O__table_kbw_j1c_npb__entry__2}

| Type | Description |
|-|-|
| AnyPublisher\<Settings, Never\> | Success: Settings - Array of SDK settings for the specified feature service. |
[Table 26. Returns]

{#NCoreServ-settingsPublisher_O__table_kbw_j1c_npb}  
The following code example shows how to call this function.

    NowSDK.core()?.settingsPublisher(for: chatService)
    .sink(receiveCompletion: { completion in
      if case .failure(let error) = completion {
        // Setting publisher failed with error
      }
    }, receiveValue: { updatedSettings in
      // Receive array of SDK settings for chatService
    })
    .store(in: &subscriptions)


