iOS용 Cloud Anchors 개발자 가이드

iOS용 ARCore SDK는 ARKit와 상호작용하여 클라우드 앵커 기능을 제공하므로 동일한 환경에서 iOS 및 Android 기기 간에 앵커를 공유할 수 있습니다.

앱에서 ARCore Cloud Anchor API 또는 ARCore 클라우드 앵커 서비스를 사용하는 방법을 알아보세요.

기본 요건

  • Xcode 버전 13.0 이상
  • Cocoapods를 사용하는 경우 Cocoapods 1.4.0 이상
  • iOS 12.0 이상을 실행하는 ARKit 호환 Apple 기기(iOS 12.0 이상의 배포 대상 필요)

클라우드 앵커를 처음 사용하는 경우:

앱에서 클라우드 앵커 사용 설정

Cloud Anchors API를 사용하려면 iOS에서 ARCore 세션 구성에 설명된 대로 GARSessionConfiguration를 만들고 cloudAnchorMode 속성을 설정해야 합니다. setConfiguration:error: (GARSession)를 사용하여 구성을 설정합니다.

또한 애플리케이션에 ARCore API를 사용 설정해야 합니다.

앵커 호스팅 및 확인

ARCore Cloud Anchor API로 클라우드 앵커를 호스팅하고 확인할 수 있습니다. API에는 완료된 작업의 콜백 메서드와 폴링할 수 있는 Future 객체가 포함되어 있습니다.

앵커 호스팅

ARAnchor를 호스팅하면 지정된 물리적 공간의 공통 좌표계에 앵커가 배치됩니다.

호스트 요청은 시각적 데이터를 Google 서버로 전송합니다. Google 서버는 현재 물리적 공간을 나타내는 좌표계에서 ARAnchor의 위치를 매핑합니다. 호스트 요청이 성공하면 새 클라우드 앵커 ID가 반환되며, 이 ID를 공유하고 나중에 앵커를 확인하는 데 사용할 수 있습니다.

- (void)addAnchorWithTransform:(matrix_float4x4)transform {
  self.arAnchor = [[ARAnchor alloc] initWithTransform:transform];
  [self.sceneView.session addAnchor:self.arAnchor];

  __weak ExampleViewController *weakSelf = self;
  self.hostFuture = [self.cloudAnchorManager
      hostCloudAnchor:self.arAnchor
           completion:^(NSString *anchorId, GARCloudAnchorState cloudState) {
             [weakSelf handleHostAnchor:anchorId cloudState:cloudState];
           }
                error:nil];
  [self enterState:HelloARStateHosting];
}

앵커 확인

ARAnchor를 확인하면 주어진 실제 공간의 Android 및 iOS 기기에서 이전에 호스팅된 앵커를 새 장면에 추가할 수 있습니다.

확인 요청은 현재 프레임의 시각적 데이터와 함께 클라우드 앵커 ID를 Google 서버에 보냅니다. 서버는 이 시각적 데이터를 현재 호스팅된 클라우드 앵커가 매핑된 이미지의 이미지와 일치시키려고 시도합니다. 해결에 성공하면 새 앵커가 세션에 추가되고 반환됩니다.

- (void)resolveAnchorWithIdentifier:(NSString *)identifier {
  GARResolveCloudAnchorFuture *garFuture =
      [self.gSession resolveCloudAnchorWithIdentifier:identifier
                                    completionHandler:completion
                                                error:&error];
}

// Pass the ARFRame to the ARCore session every time there is a frame update.
// This returns a GARFrame that contains a list of updated anchors. If your
// anchor's pose or tracking state changed, your anchor will be in the list.
- (void)cloudAnchorManager:(CloudAnchorManager *)manager didUpdateFrame:(GARFrame *)garFrame {
  for (GARAnchor *garAnchor in garFrame.updatedAnchors) {
    if ([garAnchor isEqual:self.garAnchor] && self.resolvedAnchorNode) {
      self.resolvedAnchorNode.simdTransform = garAnchor.transform;
      self.resolvedAnchorNode.hidden = !garAnchor.hasValidTransform;
    }
  }
}

선택적 GARSession 폴링 패턴

Metal을 사용 중이거나 폴링 옵션이 필요하고 동시에 앱이 최소 30fps로 실행되는 경우 다음 패턴을 사용하여 ARFrameGARSession에 전달합니다.

-(void)myOwnPersonalUpdateMethod {
  ARFrame *arFrame = arSession.currentFrame;
  NSError *error = nil;
  GARFrame *garFrame = [garSession update:arFrame error:&error];
  // your update code here
}

API 할당량

ARCore API의 요청 대역폭 할당량은 다음과 같습니다.

할당량 유형 최대 시간 적용 대상
앵커 수 무제한 N/A 프로젝트
앵커 host 요청 30 IP 주소 및 프로젝트
앵커 resolve 요청 300 IP 주소 및 프로젝트

알려진 문제 및 해결 방법

iOS용 ARCore SDK로 작업할 때 몇 가지 알려진 문제가 있습니다.

기본 스키마 설정으로 인해 앱이 간헐적으로 비정상 종료됨

GPU 프레임 캡처 및 Metal API 유효성 검사 스키마 설정은 기본적으로 사용 설정되어 있으므로 때때로 SDK 내에서 앱이 비정상 종료될 수 있습니다.

앱 비정상 종료 진단하기

비정상 종료가 발생했다고 의심될 때마다 스택 트레이스를 살펴보세요. 스택 트레이스에 MTLDebugComputeCommandEncoder가 표시되면 기본 스키마 설정 때문일 수 있습니다.

해결 방법

  1. Product > Scheme > Edit Scheme… 페이지로 이동합니다.

  2. Run 탭을 엽니다.

  3. Options 아이콘을 클릭하여 현재 설정을 확인합니다.

  4. GPU Frame CaptureMetal API Validation가 모두 사용 중지되어 있는지 확인합니다.

  5. 앱을 빌드하고 실행합니다.

알려진 추가 문제는 Cocoapods CHANGELOG를 참고하세요.

제한사항

iOS용 ARCore SDK는 ARKit setWorldOrigin(relativeTransform:) 메서드 호출을 지원하지 않습니다.

성능에 대한 고려사항

ARCore API를 사용 설정하면 메모리 사용량이 증가합니다. 네트워크 사용량과 CPU 사용률이 높기 때문에 기기의 배터리 사용량이 증가할 것으로 예상됩니다.

다음 단계