NowPushService 클래스 - iOS
NowPushService 클래스는 푸시 알림 서비스와 상호 작용할 수 있는 기능을 제공합니다.
| 이름 | 설명 |
|---|---|
| 구성 | 서비스를 초기화할 때 제공된 구성 설정입니다. 데이터 유형: NowServiceConfiguration |
NowPushService - registerPushToken(_token: Data, pushAppName: String, environment: NowPushEnvironment, completion: @escaping (Result<Data, NowPushError>) -> Void)
현재 iOS 장치 및 지정된 애플리케이션에 대한 푸시 알림을 식별하는 데 사용되는 인스턴스로 ServiceNow 고유 토큰을 등록합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| _토큰 | 데이터 | 등록할 푸시 토큰의 데이터 객체입니다. 개발자 사이트에서 가져온 Apple 토큰입니다. 자세한 내용은 개발자 안내서 - iOS를 참조하십시오Mobile SDK. |
| pushApp이름 | 문자열 | 이 토큰이 등록되는 푸시 애플리케이션의 이름입니다. |
| 환경 | NowPush환경 | 토큰이 등록되는 환경입니다. 유효한 값은 다음과 같습니다.
|
| 완료 | @escaping (Result<Data, NowPushError>) → 무효 | 토큰을 등록하려고 시도한 후 실행할 완료 핸들러입니다.
|
| 유형 | 설명 |
|---|---|
| 없음 |
이 예제에서는 TestPushApp 애플리케이션에 대한 푸시 알림 토큰을 등록하는 방법을 보여줍니다.
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)
이전에 등록한 푸시 토큰을 등록 취소합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| _토큰 | 데이터 | 등록을 취소할 푸시 토큰의 데이터 객체입니다. |
| pushApp이름 | 문자열 | 이 토큰의 등록을 취소할 푸시 애플리케이션의 이름입니다. |
| 환경 | NowPush환경 | 토큰이 등록되는 환경입니다. 유효한 값은 다음과 같습니다.
|
| 완료 | @escaping (Result<Data, NowPushError>) → 무효 | 토큰 등록 취소를 시도한 후 실행할 완료 핸들러입니다.
|
| 유형 | 설명 |
|---|---|
| 없음 |
이 예제에서는 TestPushApp 애플리케이션과 연결된 푸시 알림 토큰의 등록을 취소하는 방법을 보여줍니다.
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])
userInfo 키-값 쌍을 NowPushPayload 객체로 구문 분석합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| _userInfo | [AnyHashable: 모두] | 푸시 알림의 일부로 수신된 푸시 페이로드 컨텐츠입니다. |
| 유형 | 설명 |
|---|---|
| 결과<NowPushPayload, NowPushError> | 페이로드 구문 분석 결과를 반환합니다.
|
이 예제에서는 사용자 페이로드를 구문 분석하는 방법을 보여줍니다.
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(())
}