iOS용 이전

기본 요건

코드 이전을 시작하기 전에 다음 요구사항을 충족하는지 확인하세요.

  • ML Kit는 Xcode 13.2.1 이상을 지원합니다.
  • ML Kit는 iOS 버전 10 이상을 지원합니다.
  • ML Kit는 32비트 아키텍처 (i386 및 armv7)를 지원하지 않습니다. ML Kit는 64비트 아키텍처 (x86_64 및 arm64)를 지원합니다.
  • ML Kit 라이브러리는 코코아포드로만 제공됩니다. 프레임워크와 코코아포드를 혼합할 수 없으므로 이 라이브러리를 사용하려면 먼저 코코아포드를 사용하도록 이전해야 합니다.

Cocoapods 업데이트

앱의 Podfile에서 ML Kit iOS 코코아포드의 종속 항목을 업데이트합니다.

API이전 포드 이름새 포드 이름
바코드 스캔 Firebase/MLVision
Firebase/MLVisionBarcodeModel
GoogleMLKit/바코드 스캔
얼굴 인식 Firebase/MLVision
Firebase/MLVisionFaceModel
GoogleMLKit/FaceDetection
이미지 라벨 지정 Firebase/MLVision
Firebase/MLVisionLabelModel
GoogleMLKit/이미지 라벨 지정
객체 감지 및 추적 Firebase/MLVisionObjectDetection GoogleMLKit/ObjectDetection
텍스트 인식 Firebase/MLVision
Firebase/MLVisionTextModel
GoogleMLKit/TextRecognition
AutoML 이미지 라벨 지정 (번들 모델) Firebase/MLVisionAutoML GoogleMLKit/이미지 라벨 지정
AutoML 이미지 라벨 지정 (Firebase에서 모델 다운로드) Firebase/MLVisionAutoML GoogleMLKit/ImageLabeling커스텀
GoogleMLKit/LinkFirebase
언어 ID Firebase/MLNaturalLanguage
Firebase/MLNLLanguageID
GoogleMLKit/언어 ID
스마트 답장 Firebase/MLNaturalLanguage
Firebase/MLNLSmartReply
GoogleMLKit/SmartReply
번역 Firebase/MLNaturalLanguage
Firebase/MLNLTranslate
GoogleMLKit/번역

클래스, enum, 유형의 이름 업데이트

일반적으로 클래스 , enum 및 유형은 다음과 같이 이름을 변경해야 합니다.

  • Swift: 클래스 이름 및 enum에서 Vision 접두사 삭제
  • Objective-C: FIRVisionFIR 클래스 이름과 enum 접두사를 모두 MLK로 바꾸기

일부 클래스 이름과 유형에서는 이 일반 규칙이 적용되지 않습니다.

Swift

이전 클래스 또는 유형새 클래스 또는 유형
AutoMLLocalModel LocalModel
AutoMLRemoteModel CustomRemoteModel
VisionBarcodeDetectionCallback BarcodeScanningCallback
VisionBarcodeDetector BarcodeScanner
VisionBarcodeDetectorOptions BarcodeScannerOptions
VisionImage VisionImage (변경사항 없음)
VisionPoint VisionPoint (변경사항 없음)
VisionOnDeviceAutoMLImageLabelerOptions CustomImageLabelerOptions
VisionOnDeviceImageLabelerOptions ImageLabelerOptions

Objective-C

이전 클래스 또는 유형새 클래스 또는 유형
FIRAutoMLLocalModel MLKLocalModel
FIRAutoMLRemoteModel MLKCustomRemoteModel
FIRVisionBarcodeDetectionCallback MLKBarcodeScanningCallback
FIRVisionBarcodeDetector MLKBarcodeScanner
FIRVisionBarcodeDetectorOptions MLKBarcodeScannerOptions
FIRVisionImage MLKVisionImage
FIRVisionOnDeviceAutoMLImageLabelerOptions MLKCustomImageLabelerOptions
FIRVisionOnDeviceImageLabelerOptions MLKImageLabelerOptions
FIRVisionPoint MLKVisionPoint

Objective-C

메서드 이름 업데이트

다음 규칙에 따라 메서드 이름을 업데이트합니다.

  • 도메인 진입점 클래스 (Vision, NaturalLanguage)가 더 이상 존재하지 않습니다. 이 클래스는 작업별 클래스로 대체되었습니다. 감지기를 가져오기 위한 다양한 팩토리 메서드 호출을 각 감지기의 팩토리 메서드에 대한 직접 호출로 바꿉니다.

  • VisionImageMetadata 클래스가 VisionDetectorImageOrientation enum과 함께 삭제되었습니다. VisionImageorientation 속성을 사용하여 이미지의 표시 방향을 지정합니다.

  • TextRecognizer 인스턴스를 가져오는 onDeviceTextRecognizer 메서드의 이름이 textRecognizer로 변경되었습니다.

  • TextElement, TextLine, TextBlock를 비롯한 텍스트 인식 결과 클래스에서 신뢰도 속성이 삭제되었습니다.

  • ImageLabeler 인스턴스를 가져오는 onDeviceImageLabeleronDeviceImageLabeler(options:) 메서드가 병합되고 imageLabeler(options:)로 이름이 바뀌었습니다.

  • ObjectDetector 인스턴스를 가져오는 objectDetector 메서드를 삭제했습니다. 대신 objectDetector(options:)를 사용하세요.

  • type 속성이 ImageLabeler에서 삭제되고 entityID 속성이 이미지 라벨 지정 결과 클래스인 ImageLabel에서 삭제되었습니다.

  • Barcode Scanning API detect(in _:, completion:)의 이름이 다른 Vision API와 일관되도록 process(_:, completion:)로 변경되었습니다.

  • 이제 Natural Language API에서는 '언어 코드' 대신 BCP-47 표준에서 정의된 '언어 태그'라는 용어를 사용합니다.

  • TranslateLanguage가 이제 상수에 .en과 같은 언어 태그 대신 읽을 수 있는 이름(예: .english)을 사용합니다.

다음은 기존 Swift 메서드와 새로운 Swift 메서드의 몇 가지 예입니다.

변경 전

let options = VisionOnDeviceImageLabelerOptions()
options.confidenceThreshold = 0.75
let labeler = Vision.vision().onDeviceImageLabeler(options: options)

let detector = Vision.vision().faceDetector(options: options)

let localModel = AutoMLLocalModel(manifestPath: "automl/manifest.json")
let options = VisionOnDeviceAutoMLImageLabelerOptions(localModel: localModel)
options.confidenceThreshold = 0.75
let labeler = vision.onDeviceAutoMLImageLabeler(options: options)

let detector = Vision.vision().objectDetector()
    

신규

let options = ImageLabelerOptions()
options.confidenceThreshold = NSNumber(value:0.75)
let labeler = ImageLabeler.imageLabeler(options: options)

let detector = FaceDetector.faceDetector(options: options)

let localModel = LocalModel(manifestPath: "automl/manifest.json")
let options = CustomImageLabelerOptions(localModel: localModel)
options.confidenceThreshold = NSNumber(value:0.75)
let labeler = ImageLabeler.imageLabeler(options: options)

let detector = ObjectDetector.objectDetector(options: ObjectDetectorOptions())
    

다음은 기존 Objective-C 메서드와 새로운 Objective-C 메서드의 몇 가지 예입니다.

변경 전

FIRVisionOnDeviceImageLabelerOptions *options = 
    [[FIRVisionOnDeviceImageLabelerOptions alloc] init];
options.confidenceThreshold = 0.75;
FIRVisionImageLabeler *labeler = 
    [[FIRVision vision] onDeviceImageLabelerWithOptions:options];

FIRVisionFaceDetector *detector =
    [[FIRVision vision] faceDetectorWithOptions: options];

FIRAutoMLLocalModel *localModel =
    [[FIRAutoMLLocalModel alloc] initWithManifestPath:@"automl/manifest.json"];
FIRVisionOnDeviceAutoMLImageLabelerOptions *options =
    [[FIRVisionOnDeviceAutoMLImageLabelerOptions alloc]
        initWithLocalModel: localModel];
options.confidenceThreshold = 0.75
FIRVisionImageLabeler *labeler =
    [[FIRVision vision] onDeviceAutoMLImageLabelerWithOptions:options];

FIRVisionObjectDetector *detector =
    [[FIRVision vision] objectDetector];
    

신규

MLKImageLabelerOptions *options =
    [[MLKImageLabelerOptions alloc] init];
options.confidenceThreshold = @(0.75);
MLKImageLabeler *labeler =
    [MLKImageLabeler imageLabelerWithOptions:options];

MLKFaceDetector *detector =
    [MLKFaceDetector faceDetectorWithOptions:options];

MLKLocalModel *localModel =
    [[MLKLocalModel alloc]
        initWithManifestPath:@"automl/manifest.json"];
MLKCustomImageLabelerOptions *options =
    [[MLKCustomImageLabelerOptions alloc] initWithLocalModel:localModel];
options.confidenceThreshold = @(0.75)
MLKImageLabeler *labeler =
    [MLKImageLabeler imageLabelerWithOptions:options];

MLKObjectDetectorOptions *options = [[MLKObjectDetectorOptions alloc] init];
MLKObjectDetector *detector = [MLKObjectDetector objectDetectorWithOptions:options];
    

API별 변경사항

객체 감지 및 추적

앱에서 객체 분류를 사용하는 경우 새 SDK에서 감지된 객체의 분류 카테고리를 반환하는 방식을 변경했다는 점에 유의하세요.

VisionObjectVisionObjectCategoryObjectLabel 객체에서 정수 대신 text로 반환됩니다. 가능한 모든 문자열 카테고리는 DetectedObjectLabel enum에 포함됩니다.

.unknown 카테고리는 삭제되었습니다. 객체 분류의 신뢰도가 낮으면 분류기가 라벨을 전혀 반환하지 않습니다.

다음은 이전 Swift 코드와 새 Swift 코드의 예입니다.

변경 전

if (object.classificationCategory == .food) {
    ...
}

신규

if let label = object.labels.first {
  if (label.text == DetectedObjectLabel.food.rawValue) {
    ...
  }
}
// or
if let label = object.labels.first {
  if (label.index == DetectedObjectLabelIndex.food.rawValue) {
    ...
  }
}

다음은 이전 Objective-C 코드와 새 Objective-C 코드의 예입니다.

변경 전

if (object.classificationCategory == FIRVisionObjectCategoryFood) {
    ...
}

신규

if ([object.labels[0].text isEqualToString:MLKDetectedObjectLabelFood]) {
  ...
}
// or
if ([object.labels[0].index == MLKDetectedObjectLabelIndexFood]) {
  ...
}

Firebase 종속 항목 삭제 (선택사항)

이 단계는 다음 조건이 충족되는 경우에만 적용됩니다.

  • 사용하는 유일한 Firebase 구성요소인 Firebase ML Kit
  • 온디바이스 API만 사용합니다.
  • 모델 서빙을 사용하지 않음

이 경우 마이그레이션 후 Firebase 종속 항목을 삭제할 수 있습니다. 다음 단계를 따르세요.

  • 앱의 디렉터리와 Xcode 프로젝트에서 GoogleService-Info.plist 파일을 삭제하여 Firebase 구성 파일을 삭제합니다.
  • Podfile에서 모든 Firebase 코코아포드(예: pod 'Firebase/Analytics')를 삭제합니다.
  • 코드에서 FirebaseApp.configure()와 같은 FirebaseApp 초기화를 삭제합니다.
  • Firebase 지원 사이트의 instructions에 따라 Firebase Console에서 Firebase 앱을 삭제합니다.

도움말 보기

문제가 발생할 경우 문의할 수 있는 채널이 안내된 커뮤니티 페이지를 확인하세요.