NowData 프레임워크 - iOS

  • 릴리스 버전: Yokohama
  • 업데이트 날짜 2025년 01월 30일
  • 읽기8분
  • NowData 프레임워크에는 NowGraphQLService, NowTableService, NowAPIService(사용자 지정 API의 경우) 및 NowAttachmentService와 같은 NowData 서비스의 인스턴스화를 활성화하는 메서드가 포함되어 있습니다.

    NowData - makeApiService(instanceUrl: URL, path: String, completion: @escaping ((Result<NowApiService, NowServiceError>) -> Void))

    NowApiService의 인스턴스를 만들고 완료되면 지정된 완료 핸들러를 호출합니다.

    표 1. 매개변수
    이름 유형 설명
    instanceUrl URL ServiceNow 해당 서비스에서 REST API에 액세스할 인스턴스의 URL입니다.
    path 문자열 API 경로입니다.

    예를 들어 API 호출이 https://xxx.service-now.com/api/now/sg/incident 경우 경로는 /api/now/sg/incident입니다.

    완료 @escaping((결과<NowApiService, NowServiceError>) -> 무효) 초기화된 NowApiService 인스턴스 또는 초기화가 실패한 이유를 나타내는 NowServiceError를 포함하는 Result<NowApiService, NowServiceError>와 함께 호출되는 완료 핸들러입니다.
    표 2. 반환
    유형 설명
    안 함

    다음 코드 예제에서는 이 함수를 호출하는 방법을 보여 줍니다.

    let path = "api/now/sg"
    let apiPublisher = apiService(for: path)
    
    func apiService(for path: String) -> AnyPublisher<NowAPIService, ConfigurationError> {
      guard let instanceURL else {
        return Fail(error: ConfigurationError.invalidInstanceURL)
        .eraseToAnyPublisher()
      }
      return Future { promise in
        NowData.makeApiService(instanceUrl: instanceURL, path: path) { (result) in
          promise(result.mapError { .sdkError($0) })
        }
      }
      .eraseToAnyPublisher()
    }

    NowData - makeAttachmentService(instanceUrl: URL, completion: @escaping ((Result<NowAttachmentService, NowServiceError>) -> Void))

    NowAttachmentService의 인스턴스를 만들고 완료 후 지정된 완료 처리기를 호출합니다.

    표 3. 매개변수
    이름 유형 설명
    instanceUrl URL ServiceNow 서비스가 첨부 파일에 액세스할 인스턴스의 URL입니다.
    완료 @escaping((결과<NowAttachmentService, NowServiceError>) -> 무효) 초기화된 NowAttachmentService 인스턴스 또는 초기화가 실패한 이유를 나타내는 NowServiceError를 포함하는 Result<NowAttachmentService, NowServiceError>로 호출되는 완료 처리기입니다.
    표 4. 반환
    유형 설명
    안 함

    다음 코드 예제에서는 이 함수를 호출하는 방법을 보여 줍니다.

    ….
    guard 
      let jwtUrl = URL(string: "http://13.57.38.237:8080"),
      let instanceUrl = URL(string: "https://mobilecoresdk.service-now.com") else {
        return
      }
    
    // AuthorizationProvider – struct conforming to NowSDKAuthorizationProviding protocol
    let authorizationProvider = AuthorizationProvider(userEmail: "sdk@servicenow.com", jwtProviderUrl: jwtUrl, clientId: "deb8756b452d201039231ca568f26511")
            
    // PermissionProvider – class conforming to DevicePermissionDelegate protocol
    let permissionProvider = PermissionProvider()
    let config = NowSDKConfiguration(authorizationProvider: authorizationProvider, permissionDelegate: permissionProvider, logLevel: .debug)
    	
    do {
      try NowSDK.configure(with: config)
      initializeAttachmentService (with: instanceURL)
    } catch {
      // Return ConfigurationError.sdkError(error)
    }
    …..
    
    func initializeAttachmentService(instanceUrl: instanceURL) { result in
      switch result {
        case .success(let service)
          self?.attachmentService = service
        case .failure(let error)
          debug.print(“Creating Attachment service failed with error: \(error.localizedDescription)”)
          self?.attachmentService = nil
      }
    }
    

    NowData - makeGraphQLService(instanceUrl: URL, completion: @escaping ((Result<NowGraphQLService, NowServiceError>) -> Void))

    NowGraphQLService의 인스턴스를 만들고, 완료되면 지정된 완료 핸들러를 호출합니다.

    표 5. 매개변수
    이름 유형 설명
    instanceUrl URL ServiceNow GraphQL 서비스를 제공하는 인스턴스의 URL입니다.
    완료 @escaping ((결과<NowGraphQLService, NowServiceError>) -> 무효) 초기화된 NowGraphQLService 인스턴스 또는 초기화가 실패한 이유를 나타내는 NowServiceError를 포함하는 Result<NowGraphQLService, NowServiceError>와 함께 호출되는 완성 핸들러입니다.
    표 6. 반환
    유형 설명
    안 함

    func initializeGraphQLService(instanceUrl: URL) {
      makeGraphQLService(instanceUrl: instanceUrl) { [weak self] result in
        switch result {
        case .success(let service):
          self?.graphQLService = service
        case .failure(let error):
          debugPrint("Creating GraphQL service failed with error: \(error.localizedDescription)")
          self?.graphQLService = nil
        }
      }
    }

    NowData - makeTableService(instanceUrl: URL, completion: @escaping ((Result<NowTableService, NowServiceError>) -> Void))

    NowTableService의 인스턴스를 만들고 완료된 후 지정된 완료 처리기를 호출합니다.

    표 7. 매개변수
    이름 유형 설명
    instanceUrl URL ServiceNow 서비스가 테이블에 액세스할 인스턴스의 URL입니다.
    완료 @escaping ((result<NowTableService, NowServiceError>) -> void) 초기화된 NowTableService 인스턴스 또는 초기화가 실패한 이유를 나타내는 NowServiceError를 포함하는 Result<NowTableService, NowServiceError>와 함께 호출되는 완성 처리기입니다.
    표 8. 반환
    유형 설명
    안 함

    다음 코드 예제에서는 이 함수를 호출하는 방법을 보여 줍니다.

    func initializeTableService(for instanceUrl: URL) {
      makeTableService(instanceUrl: instanceUrl) { [weak self] result in
        guard let self = self else { return }
                
        switch result {
          case .success(let tableService):
            self.tableService = tableService
            // Create a Paginator that will iterate over pages of customer support cases. The Paginator's response type will be
            // inferred from the Paginator's type definition (e.g. `Paginator<[CustomerServiceCase]>`).
            self.paginator = tableService.paginator(from: Self.tableName, configuration: self.fetchConfiguration)
            // Subscribe to the Paginator's publisher so we will be able to receive paged results.
            self.subscribeToPaginatorPublisher()
            // As we are now ready to start fetching data, inform the view controller.
            self.onReady(self)
          case .failure(let error):
            debugPrint("Creating table service failed with error: \(error.localizedDescription)")
            self.tableService = nil
            self.paginator = nil
        }
      }
    }