iOS 소비자 SDK 모듈화 마이그레이션

iOS용 소비자 SDK를 사용하면 모듈식 아키텍처를 사용하여 차량 공유 앱을 만들 수 있습니다. API에서 특정 앱에 사용하려는 부분을 자체 API와 통합할 수 있습니다. 다양한 기능의 Consumer SDK API는 별도의 모듈로 캡슐화됩니다.

차량 공유 앱에서 이전 버전의 소비자 SDK를 사용하는 경우 이 모듈식 아키텍처를 사용하도록 앱을 업그레이드해야 합니다. 이 이전 가이드에서는 앱을 업그레이드하는 방법을 설명합니다.

개요

소비자 SDK 모듈식 아키텍처에는 사용자 인터페이스 상태를 보유하는 MapViewSession 객체가 도입되었습니다. 이전 버전의 Consumer SDK에서는 앱이 상태 간에 전송되었습니다. 이 모듈식 아키텍처를 사용하여 MapViewSession 객체를 만들고 지도에 세션을 표시할 수 있습니다. 세션이 표시되지 않으면 iOS용 Maps SDK만 사용할 때와 동일한 콘텐츠가 지도에 표시됩니다.

MapViewSession 객체는 모듈의 단일 수명 주기 사용 인스턴스를 나타냅니다. 세션은 모듈 API의 액세스 포인트입니다. 예를 들어 탐색 여정 공유 세션은 단일 이동을 따릅니다. JourneySharingSession 객체와 상호작용하여 이동을 모니터링합니다.

TripModel 객체

이전 버전의 Consumer SDK에서는 TripService 인스턴스를 사용하여 한 번에 하나의 실시간 이동만 모니터링할 수 있었습니다. TripModel 객체를 사용하면 하나의 TripService 인스턴스에서 여러 실시간 이동을 모니터링할 수 있습니다. TripModel의 인스턴스는 TripService에서 만들 수 있으며, TripModel의 각 인스턴스는 특정 이동에 결합됩니다.

등록된 구독자가 업데이트될 때 이동 중인 경우 TripModel 인스턴스는 업데이트 이벤트를 호출합니다.

TripModel 객체를 사용하여 JourneySharingSession 객체의 인스턴스를 만들 수도 있습니다.

MapViewSession

MapViewSession 인스턴스는 한 번에 하나의 mapView에만 추가할 수 있으며 다음 두 상태 중 하나일 수 있습니다.

  • GMTCMapViewSessionStateInactive 상태는 이 MapViewSession가 아직 mapView에 추가되지 않았거나 mapView에서 삭제되었음을 나타냅니다. MapViewSession 인스턴스가 mapView에서 삭제되면 didRemoveFromMapView 메서드가 호출됩니다.

    hideMapViewSession 또는 hideAllMapViewSessions 메서드를 호출하면 mapView에서 mapViewSession가 삭제됩니다.

    [_mapView hideMapViewSession:mapViewSessionA];
    

    또는

    [_mapView hideAllMapViewSessions];
    
  • GMTCMapViewSessionStateActive 상태는 이 MapViewSessionmapView에 추가되었음을 나타냅니다. MapViewSession의 인스턴스가 mapView에 추가되면 didAddToMapView 메서드가 호출됩니다. showMapViewSession 메서드를 호출하면 mapViewSession가 타겟 mapView에 추가됩니다.

    [_mapView showMapViewSession:mapViewSessionA];
    

데이터 전용 및 사용자 인터페이스 구성요소 사용

데이터 전용 구성요소 또는 주문형 차량 및 배달 솔루션에서 제공하는 사용자 인터페이스 요소 API를 사용하여 차량 공유 앱을 만들 수 있습니다.

데이터 전용 구성요소 사용

데이터 전용 구성요소를 사용하여 차량 공유 앱을 만들려면 다음 단계를 따르세요.

  1. 제공업체 ID와 액세스 토큰 제공자를 지정하여 GMTCServices 객체를 초기화합니다.
  2. GMTCServices 객체의 공유 인스턴스에서 tripService 속성을 가져옵니다.
  3. tripService 객체의 tripModelForTripName 메서드를 사용하여 지정된 이동에 대한 GMTCTripModel 객체의 인스턴스를 만들거나 가져옵니다.
  4. GMTCTripModel 인스턴스에 콜백을 등록하여 이동 모니터링을 시작합니다.

다음 예에서는 데이터 전용 구성요소를 사용하는 방법을 보여줍니다.

[GMTCServices setAccessTokenProvider:[[AccessTokenProvider alloc] init]
                          providerID:yourProviderID];
GMTCTripService *tripService = [GMTCServices sharedServices].tripService;

// Create a tripModel instance for listening to updates to the trip specified by this trip name.
GMTCTripModel *tripModel = [tripService tripModelForTripName:tripName];

// Register for the trip update events.
[tripModel registerSubscriber:self];

// To stop listening for the trip update.
[tripModel unregisterSubscriber:self];

UI 요소 API 사용

다음 절차에 따라 주문형 차량 공유 서비스 솔루션 사용자 인터페이스 요소 API를 사용하여 소비자 앱을 만듭니다.

  1. 제공업체 ID와 액세스 토큰 제공자를 지정하여 GMTCServices 객체를 초기화합니다.
  2. 기본 지도를 렌더링하기 위한 GMTCMapView 객체를 초기화합니다.
  3. GMTCServices 객체의 공유 인스턴스에서 tripService 속성을 가져옵니다.
  4. tripService 객체의 tripModelForTripName 메서드를 사용하여 지정된 이동에 대한 GMTCTripModel 객체의 인스턴스를 만들거나 가져옵니다.
  5. GMTCTripModel 인스턴스로 GMTCJourneySharingSession 객체를 만듭니다.
  6. mapViewGMTCJourneySharingSession 객체를 표시합니다.
  7. GMTCTripModel 인스턴스에 콜백을 등록하여 이동 모니터링을 시작합니다.

다음 예에서는 사용자 인터페이스 API를 사용하는 방법을 보여줍니다.

[GMTCServices setAccessTokenProvider:[[AccessTokenProvider alloc] init]
                          providerID:yourProviderID];
GMTCTripService *tripService = [GMTCServices sharedServices].tripService;

// Create a tripModel instance for listening to updates to the trip specified by this trip name.
GMTCTripModel *tripModel = [tripService tripModelForTripName:tripName];
GMTCJourneySharingSession *journeySharingSession =
  [[GMTCJourneySharingSession alloc] initWithTripModel:tripModel];

// Add the journeySharingSession instance on the mapView for UI updating.
[self.mapView showMapViewSession:journeySharingSession];

// Register for the trip update events.
[tripModel registerSubscriber:self];

// To remove the JourneySharingSession from the mapView:
[self.mapView hideMapViewSession:journeySharingSession];

// To stop listening for the trip update.
[tripModel unregisterSubscriber:self];

모듈식 아키텍처 코드 변경사항

차량 공유 앱에서 이전 버전의 소비자 SDK를 사용하는 경우 업데이트된 모듈식 아키텍처에서 코드를 일부 변경해야 합니다. 이 섹션에서는 이러한 변경사항 중 일부를 설명합니다.

경로 모니터링

업데이트된 모듈식 아키텍처를 사용하려면 데이터 레이어 및 사용자 인터페이스 사용자 모두의 코드를 변경해야 합니다.

이전 버전에서는 데이터 영역 사용자가 다음 코드를 사용하여 경로 모니터링을 처리할 수 있었습니다.

GRCTripRequest *tripRequest =
    [[GRCTripRequest alloc] initWithRequestHeader:[GRSRequestHeader defaultHeader]
                                         tripName:tripName
                          autoRefreshTimeInterval:1];
GRCTripService *tripService = [GRCServices sharedServices].tripService;
[tripService registerServiceSubscriber:self];
[tripService setActiveTripWithRequest:tripRequest];

모듈식 아키텍처를 사용하면 데이터 영역 사용자는 다음 코드를 사용할 수 있습니다.

GMTCTripService *tripService = [GMTCServices sharedServices].tripService;
GMTCTripModel *tripModel = [tripService tripModelForTripName:tripName];
tripModel.options.autoRefreshTimeInterval = 1;
[tripModel registerSubscriber:self];

이전 버전에서는 사용자 인터페이스 사용자가 다음 코드를 사용하여 경로 모니터링을 처리할 수 있습니다.

// Show the Journey Sharing user interface.
[self.mapView startTripMonitoring];

// Hide the Journey Sharing user interface.
[self.mapView resetCustomerState];

모듈식 아키텍처를 사용하면 사용자 인터페이스 사용자는 다음 코드를 사용할 수 있습니다.

// Show the Journey Sharing user interface.
GMTCJourneySharingSession *journeySharingSession =
  [[GMTCJourneySharingSession alloc] initWithTripModel:tripModel];
[self.mapView showMapViewSession:journeySharingSession];

// Hide the Journey Sharing user interface.
[self.mapView hideMapViewSession:journeySharingSession];