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


---

# NowPushService class - iOS

# NowPushService class - iOS {#ariaid-title1}

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

The NowPushService class provides functions that enable interaction
with the Push Notification service.
{#NowPushServiceiOSAPI__entry__2}

| Name | Description |
|-|-|
| configuration | Configuration settings provided when the service was initialized. Data type: [NowServiceConfiguration](https://servicenow-prod.fluidtopics.net/A6W2zQ0fOO_VQ9lbo3VKwQ#NowServiceConfigurationiOSStruct "The NowServiceConfiguration structure defines configuration information for a feature service.") |
[Table 1. Properties]

## NowPushService - registerPushToken(_token: Data, pushAppName: String, environment:
NowPushEnvironment, completion: @escaping (Result\<Data, NowPushError\>) -\> Void) {#ariaid-title2}

Registers a unique token with the ServiceNow instance used to
identify the push notifications for the current iOS device and specified
application.
{#NPushServ-registerPushToken_O_S_O_O__table_cr3_pgh_trb__entry__3}

| Name | Type | Description |
|-|-|-|
| _token | Data | Data object of the push token to register. This is the token obtained from the Apple Developer site. For more information, see the Mobile SDK Developer Guide - iOS. |
| pushAppName | String | Name of the push application for which this token is being registered. |
| environment | NowPushEnvironment | Environment for which the token is being registered. Valid values: * production * sandbox |
| completion | @escaping (Result​\<Data, NowPushError\>) → Void | Completion handler to execute after the token has been attempted to be registered. * Success: iOS push notification certificate. * Error: NowPushError - Information about the error that occurred when trying to register the token. Possible values: * decoding: Decoding error occurred. * httpRequestFailure: Generic error that is returned whenever the http call is not a success (2xx). * notAuthorized: Requestor is not authorized to perform the specified push notification operation. * unsupportedData: Push payload is invalid. {#NPushServ-registerPushToken_O_S_O_O__ul_pmt_m5h_trb} {#NPushServ-registerPushToken_O_S_O_O__ul_lxy_k3h_trb} |
[Table 2. Parameters]

{#NPushServ-registerPushToken_O_S_O_O__table_cr3_pgh_trb} {#NPushServ-registerPushToken_O_S_O_O__table_dr3_pgh_trb__entry__2}

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

{#NPushServ-registerPushToken_O_S_O_O__table_dr3_pgh_trb}  
This example shows how to register a push notification token for the TestPushApp
application.

    func registerForPushNotifications(deviceToken: Data) {
      pushService.registerPushToken(deviceToken,
          pushAppName: "TestPushApp",
          environment: environment) { [weak self] result in
        guard let self = self else { return }
        switch result {
          case .success:
            UserDefaults.standard.set(true, forKey: "pushNotificationsRegistered")
            self.pushRegistrationState = .registrationSuccess
          case .failure:
            UserDefaults.standard.set(false, forKey: "pushNotificationsRegistered")
            self.pushRegistrationState = .registrationFailed
        }
      }
    }

## NowPushService - unregisterPushToken(_token: Data, pushAppName: String, environment:
NowPushEnvironment, completion: @escaping (Result\<Data, NowPushError\>) -\> Void) {#ariaid-title3}

Unregisters a previously registered push token.
{#NPushServ-unregisterPushToken_O_S_O_O__table_fvk_rjh_trb__entry__3}

| Name | Type | Description |
|-|-|-|
| _token | Data | Data object of the push token to unregister. |
| pushAppName | String | Name of the push application for which this token is being unregistered. |
| environment | NowPushEnvironment | Environment for which the token is being registered. Valid values: * production * sandbox |
| completion | @escaping (Result​\<Data, NowPushError\>) → Void | Completion handler to execute after the token has been attempted to be unregistered. * Success: API response data. * Error: `NowPushError` - Information about the error that occurred when trying to unregister the token. Possible values: * decoding: Decoding error occurred. * httpRequestFailure: Generic error that is returned whenever the http call is not a success (2xx). * notAuthorized: Requestor is not authorized to perform the specified push notification operation. * unsupportedData: Push payload is invalid. {#NPushServ-unregisterPushToken_O_S_O_O__ul_pmt_m5h_trb} {#NPushServ-unregisterPushToken_O_S_O_O__ul_lxy_k3h_trb} |
[Table 4. Parameters]

{#NPushServ-unregisterPushToken_O_S_O_O__table_fvk_rjh_trb} {#NPushServ-unregisterPushToken_O_S_O_O__table_gvk_rjh_trb__entry__2}

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

{#NPushServ-unregisterPushToken_O_S_O_O__table_gvk_rjh_trb}  
This example shows how to unregister the push notification token associated with the
TestPushApp application.

    func unregisterFromPushNotifications(deviceToken: Data) {
      pushService.unregisterPushToken(deviceToken, pushAppName: "TestPushApp", environment: environment) { [weak self] result in
        guard let self = self else { return }
        switch result {
          case .success:
            UserDefaults.standard.set(false, forKey: "pushNotificationsRegistered")
            self.pushRegistrationState = .unregisterSuccess
          case .failure:
            self.pushRegistrationState = .unregisterFailed
        }
      }
    }

## NowPushService - payloadFromUserInfo(_userInfo: \[AnyHashable: Any\]) {#ariaid-title4}

Parses the `userInfo` key-value pairs into a
`NowPushPayload` object.
{#NPushServ_payloadFromUserInfo_O__table_vqs_mkh_trb__entry__3}

| Name | Type | Description |
|-|-|-|
| _userInfo | \[AnyHashable: Any\] | Push payload content received as part of the push notification. |
[Table 6. Parameters]

{#NPushServ_payloadFromUserInfo_O__table_vqs_mkh_trb} {#NPushServ_payloadFromUserInfo_O__table_wqs_mkh_trb__entry__2}

| Type | Description |
|-|-|
| Result\<NowPushPayload, NowPushError\> | Returns the results of the payload parsing. * Success: Parsed `NowPushPayload` object. * Failure: `NowPushError` - Information about the error that was encountered while parsing the specified user payload. Possible values: * decoding: Decoding error occurred. * httpRequestFailure: Generic error that is returned whenever the http call is not a success (2xx). * notAuthorized: Requestor is not authorized to perform the specified push notification operation. * unsupportedData: Push payload is invalid. {#NPushServ_payloadFromUserInfo_O__ul_pmt_m5h_trb} |
[Table 7. Returns]

{#NPushServ_payloadFromUserInfo_O__table_wqs_mkh_trb}  
This example shows how to parser a user payload.

    func userNotificationCenter(_ center: UNUserNotificationCenter,
        didReceive response: UNNotificationResponse,
        withCompletionHandler completionHandler: @escaping () -> Void) {
      guard let pushService = pushService else {
        completionHandler()
        return
      }
      let userInfo = response.notification.request.content.userInfo
      _ = pushService.payloadFromUserInfo(userInfo)
        .flatMap(handleNowPushPayload)
    }


    func handleNowPushPayload(_ payload: NowPushPayload) -> Result<Void, NowPushError> {
      guard payload is NowPushVirtualAgent else {
        return .failure(NowPushError.unsupportedData)
      }
      launchVirtualAgent()
      return .success(())
    }


