---
sourceDocument: Xanadu API 참조
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ko-KR/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - ko-KR

ft:publication_title :

    - Xanadu API 참조

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# 애플리케이션에서 iOS 푸시 알림 설정

# 애플리케이션에서 iOS 푸시 알림 설정 {#ariaid-title1}

* 릴리스 버전: Xanadu
* 
* 업데이트 날짜 2024년 08월 01일
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 소요 시간: 5분

푸시 알림을 구성하기 위해 인스턴스에서 ServiceNow 수행해야 하는 작업 외에도 애플리케이션에 특정 코드를 포함해야 합니다 iOS .

## NowSDK NowPushService 생성 {#mobsdk-ios-setup-push-app__section_hyb_zxp_prb}

애플리케이션에서 가장 먼저 수행해야 하는 작업 중 하나는 `NowPushService`를 만드는 것입니다. `NowPush` SDK는 이 서비스를 생성하기 위한 팩토리 기능을 제공합니다. 기본 코드 본문 초기에 다음 코드 조각과 유사한 코드를 추가합니다.

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

NowPush.makePushService() 메서드에 대한 자세한 내용은 을 참조하십시오[NowPush API - iOS](https://servicenow-prod.fluidtopics.net/yyVCrFWdd8KDlmb6j0pLpw#NowPushiOSAPI "NowPush API는 사용자가 NowPush 서비스 인스턴스를 인스턴스화하는 데 사용할 수 있는 최상위 글로벌 API입니다.").

## 푸시 토큰 등록 {#mobsdk-ios-setup-push-app__section_kyr_4cq_prb}

Apple 는 푸시 알림을 수신할 장치와 애플리케이션을 식별하는 고유한 푸시 알림 토큰을 제공합니다. 애플리케이션이 푸시 알림을 수신하려면 `NowPushService`를 사용하여 이 토큰을 등록해야 합니다. 응용 프로그램에 다음 코드 조각 iOS 과 유사한 함수를 추가합니다. 이 애플리케이션은 인스턴스에 등록되어 있어야 합니다 ServiceNow .

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

registerPushToken() 메서드에 대한 자세한 내용은 을 참조하십시오[NowPushService - registerPushToken(_token: Data, pushAppName: String, environment: NowPushEnvironment, completion: @escaping (Result\<data, NowPushError\>) - \> void)](https://servicenow-prod.fluidtopics.net/emNW3DnQd0_o6jER~SaAqA#NPushServ-registerPushToken_O_S_O_O "현재 iOS 장치 및 지정된 애플리케이션에 대한 푸시 알림을 식별하는 데 사용되는 인스턴스에 고유 토큰을 ServiceNow 등록합니다.").

## 푸시 토큰 등록 취소

사용자가 애플리케이션을 종료할 때마다(예: 사용자가 로그아웃할 때) 푸시 토큰의 등록을 취소해야 합니다. 다음 코드 조각과 유사한 코드를 사용하여 푸시 토큰의 등록을 취소합니다. 애플리케이션의 이름으로 변경 pushAppName 해야 합니다 iOS .

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

unregisterPushToken() 메서드에 대한 자세한 내용은 을 참조하십시오[NowPushService - unregisterPushToken(_token: 데이터, pushAppName: 문자열, 환경: NowPushEnvironment, 완료: @escaping(결과\<데이터, NowPushError\>) - \> 무효)](https://servicenow-prod.fluidtopics.net/emNW3DnQd0_o6jER~SaAqA#NPushServ-unregisterPushToken_O_S_O_O "이전에 등록된 푸시 토큰을 등록 취소합니다.").

## 푸시 페이로드 구문 분석 {#mobsdk-ios-setup-push-app__section_ofn_dlw_trb}

푸시 알림 페이로드를 `NowPushPayload` 개체로 구문 분석하여 정보를 수집하고 애플리케이션의 다른 부분에서 데이터를 사용해야 합니다. 현재는 가상 에이전트 푸시 알림에만 사용할 수 있습니다. 다음과 유사한 코드를 사용합니다

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


