---
sourceDocument: Brazil API Reference
sourceDocumentLink: https://www.servicenow.com/docs/r/api-reference

 Release :

    - brazil

ft:locale :

    - en-US

ft:publication_title :

    - Brazil API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Setting up push notifications in your iOS application

# Setting up push notifications in your iOS application {#ariaid-title1}

Release version: Brazil  
Updated September 10, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 minutes to read
Summarize  
![AI sparkle icon](https://servicenow.com/docs/portal-asset/ai-sparkle-icon) Summarized using AI  
This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.  

## Summary of Setting up push notifications in your iOS application

This guide explains how to configure push notifications in your iOS application integrated with ServiceNow.
Beyond configuring settings in your ServiceNow instance, you must implement specific code within your iOS app using the NowPush SDK to enable push notification functionality.
Show full answer Show less  

## Key Steps for Implementation

* **Create the NowPushService:** Use the NowPush SDK's factory method `NowPush.makePushService()` to instantiate the push notification service early in your app's main code. This sets up the foundation for managing push notifications.
* **Register the push token:** Apple issues a unique device token required to receive push notifications. Register this token with the NowPushService using `registerPushToken()`, specifying your iOS application name and environment. Successful registration enables your app to receive notifications from your ServiceNow instance.
* **Unregister the push token:** When a user logs out or exits the app, unregister the device token with `unregisterPushToken()` to stop receiving notifications. This helps maintain security and proper token lifecycle management.
* **Parse push payloads:** To handle incoming notifications, especially Virtual Agent messages, parse the payload into a `NowPushPayload` object using the SDK method `payloadFromUserInfo()`. Implement handlers to process this data appropriately within your app.

## Why This Matters

Following these steps ensures your iOS application is correctly registered and synchronized with your ServiceNow instance for push notifications. It enables real-time communication such as alerts and Virtual Agent interactions, enhancing user engagement and responsiveness.

## What to Expect

* Reliable setup of push notification services within your iOS app using the NowPush SDK.
* Seamless registration and unregistration of device tokens tied to your ServiceNow instance.
* Effective parsing and handling of push notification payloads, especially for Virtual Agent use cases.  
In addition to the tasks that you must perform on your ServiceNow instance to configure a push notification, you must also include specific code in your iOS application.

## Create the NowSDK NowPushService {#mobsdk-ios-setup-push-app__section_hyb_zxp_prb}

One of the first things that needs to be done in your application is to create a
`NowPushService`. The `NowPush` SDK provides a factory
function to create this service. Add code similar to the following snippet early within your
main code body.

    func setup(with instanceURL: URL) -> AnyPublisher<NowService, ConfigurationError> {
      NowPush.makePushService(instanceUrl: instanceURL)
        .mapError { .sdkError($0) }
        .map { $0 as NowService }
        .eraseToAnyPublisher()
    }

For additional information on the NowPush.makePushService() method, refer to [NowPush API - iOS](https://www.servicenow.com/docs/VSwmlm82ci5Fz~Gl9mZeBQ#NowPushiOSAPI "The NowPush API is a top-level global API that enables users to instantiate a NowPush service instance.").

## Register the push token {#mobsdk-ios-setup-push-app__section_kyr_4cq_prb}

Apple provides a unique push notification token that identifies the device and application to receive push notifications. In order for an application to receive push notification, you must register this token using
the `NowPushService`. Add a function similar to the following code snippet in your iOS application. This application must be registered with your ServiceNow instance.

    func registerForPushNotifications(deviceToken: Data) {
      pushService.registerPushToken(deviceToken,
          pushAppName: "TestPushApp", // Modify this to be your iOS application name
          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
        }
      }
    }

For additional information on the registerPushToken() method, refer to [NowPushService - registerPushToken(_token: Data, pushAppName: String, environment: NowPushEnvironment, completion: @escaping (Result\<Data, NowPushError\>) -\> Void)](https://www.servicenow.com/docs/mNYkA7dXREguKwXtal3e_Q#NPushServ-registerPushToken_O_S_O_O "Registers a unique token with the ServiceNow instance used to identify the push notifications for the current iOS device and specified application.").

## Unregister the push token

You need to unregister a push token whenever the user exits your application, such as when the user logs out. Use code similar to the following code snippet to unregister a push token. Ensure that you change
pushAppName to the name of your iOS 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
        }
      }
    }

For additional information on the unregisterPushToken() method, refer to [NowPushService - unregisterPushToken(_token: Data, pushAppName: String, environment: NowPushEnvironment, completion: @escaping (Result\<Data, NowPushError\>) -\> Void)](https://www.servicenow.com/docs/mNYkA7dXREguKwXtal3e_Q#NPushServ-unregisterPushToken_O_S_O_O "Unregisters a previously registered push token.").

## Parse push payload {#mobsdk-ios-setup-push-app__section_ofn_dlw_trb}

You will need to parse push notification payloads into a `NowPushPayload`
object to collect information and to use the data in other parts of the application.
Currently, this is only available for Virtual Agent push notifications. Use code similar to
the following

    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(())
    }


