Page Summary
-
Migrate your iOS app to the standalone ML Kit SDK by updating CocoaPods dependencies, renaming classes and methods, and addressing API-specific changes.
-
Ensure your project meets the prerequisites, including Xcode 13.2.1 or later, iOS 15.5 or later, 64-bit architecture, and CocoaPods usage.
-
Consult the provided tables for specific class, enum, type, and method name changes in Swift and Objective-C.
-
Consider removing Firebase dependencies if you solely utilize on-device ML Kit APIs and don't use model serving or other Firebase components.
-
Refer to the Community page for support and troubleshooting assistance during the migration process.
This guide explains how to migrate away from ML Kit for Firebase for iOS.
Prerequisites
Before you start to migrate your code, be sure you meet these requirements:
- ML Kit supports Xcode 13.2.1 or greater.
- ML Kit supports iOS version 15.5 or greater.
- ML Kit does not support 32-bit architectures (i386 and armv7). ML Kit does support 64-bit architectures (x86_64 and arm64).
- The ML Kit library is only provided as cocoapods. You can't mix frameworks and cocoapods, so in order to use this library you need to first migrate to use cocoapods.
Update Cocoapods
Update the dependencies for the ML Kit iOS cocoapods in your app's Podfile:
| API | Old pod name(s) | New pod name(s) |
|---|---|---|
| Barcode scanning | Firebase/MLVision Firebase/MLVisionBarcodeModel |
GoogleMLKit/BarcodeScanning |
| Face detection | Firebase/MLVision Firebase/MLVisionFaceModel |
GoogleMLKit/FaceDetection |
| Image labeling | Firebase/MLVision Firebase/MLVisionLabelModel |
GoogleMLKit/ImageLabeling |
| Object detection and tracking | Firebase/MLVisionObjectDetection | GoogleMLKit/ObjectDetection |
| Text recognition | Firebase/MLVision Firebase/MLVisionTextModel |
GoogleMLKit/TextRecognition |
| AutoML image labeling (bundled model) | Firebase/MLVisionAutoML | GoogleMLKit/ImageLabelingCustom |
| AutoML image labeling (model downloaded) | Firebase/MLVisionAutoML | GoogleMLKit/ImageLabelingCustom To host and download custom models, move your models to Cloud Storage and add download logic in your app to load them as local models. For details, see the Firebase ML to Cloud Storage migration guide. |
| Language ID | Firebase/MLNaturalLanguage Firebase/MLNLLanguageID |
GoogleMLKit/LanguageID |
| Smart reply | Firebase/MLNaturalLanguage Firebase/MLNLSmartReply |
GoogleMLKit/SmartReply |
| Translate | Firebase/MLNaturalLanguage Firebase/MLNLTranslate |
GoogleMLKit/Translate |
Update names of classes, enums, and types
In general, classes, enums, and types need to be renamed as follows:
- Swift: Remove the
Visionprefix from class names and enums - Objective-C: Replace both
FIRVisionandFIRclass name and enum prefixes byMLK
For some class names and types this general rule does not apply:
Swift
| Old class or type | New class or type |
|---|---|
| AutoMLLocalModel | LocalModel |
| AutoMLRemoteModel | LocalModel Requires manual download. Firebase-hosted remote models are deprecated. For details, see the Firebase ML to Cloud Storage migration guide. |
| VisionBarcodeDetectionCallback | BarcodeScanningCallback |
| VisionBarcodeDetector | BarcodeScanner |
| VisionBarcodeDetectorOptions | BarcodeScannerOptions |
| VisionImage | VisionImage (no change) |
| VisionPoint | VisionPoint (no change) |
| VisionOnDeviceAutoMLImageLabelerOptions | CustomImageLabelerOptions |
| VisionOnDeviceImageLabelerOptions | ImageLabelerOptions |
Objective-C
| Old class or type | New class or type |
|---|---|
| FIRAutoMLLocalModel | MLKLocalModel |
| FIRAutoMLRemoteModel | MLKLocalModel Requires manual download. Firebase-hosted remote models are deprecated. For details, see the Firebase ML to Cloud Storage migration guide. |
| FIRVisionBarcodeDetectionCallback | MLKBarcodeScanningCallback |
| FIRVisionBarcodeDetector | MLKBarcodeScanner |
| FIRVisionBarcodeDetectorOptions | MLKBarcodeScannerOptions |
| FIRVisionImage | MLKVisionImage |
| FIRVisionPoint | MLKVisionPoint |
| FIRVisionOnDeviceAutoMLImageLabelerOptions | MLKCustomImageLabelerOptions |
| FIRVisionOnDeviceImageLabelerOptions | MLKImageLabelerOptions |
Update method names
Update method names according to these rules:
Domain entry point classes (
Vision,NaturalLanguage) no longer exist. They have been replaced by task specific classes. Replace calls to their various factory methods for getting detectors with direct calls to each detector's factory method.The
VisionImageMetadataclass has been removed, along with theVisionDetectorImageOrientationenum. Use theorientationproperty ofVisionImageto specify the display orientation of an image.The
onDeviceTextRecognizermethod that gets a newTextRecognizerinstance has been renamed totextRecognizer.The confidence property has been removed from text recognition result classes, including
TextElement,TextLine, andTextBlock.The
onDeviceImageLabelerandonDeviceImageLabeler(options:)methods to get a newImageLabelerinstance have been merged and renamed toimageLabeler(options:).The
objectDetectormethod to get a newObjectDetectorinstance has been removed. UseobjectDetector(options:)instead.The
typeproperty has been removed fromImageLabelerand theentityIDproperty has been removed from the image labeling result class,ImageLabel.The barcode scanning API
detect(in _:, completion:)has been renamed toprocess(_:, completion:)to be consistent with other vision APIs.The Natural Language APIs now use the term "language tag" (as defined by the BCP-47 standard) instead of "language code".
TranslateLanguagenow uses readable names (like.english) for its constants instead of language tags (like.en).
Here are some examples of old and new Swift methods:
Old
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()
New
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())
Here are some examples of old and new Objective-C methods:
Old
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];
New
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-specific changes
Object detection and tracking
If your app uses object classification, be aware that the new SDK has changed the way it returns the classification category for detected objects.
VisionObjectCategory in VisionObject is returned as text in an
ObjectLabel object, instead of an integer. All possible string categories are
included in the DetectedObjectLabel enum.
Note that the .unknown category has been removed. When the confidence of
classifying an object is low, the classifier returns no label at all.
Here is an example of the old and new Swift code:
Old
if (object.classificationCategory == .food) {
...
}New
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) {
...
}
}Here is an example of the old and new Objective-C code:
Old
if (object.classificationCategory == FIRVisionObjectCategoryFood) {
...
}New
if ([object.labels[0].text isEqualToString:MLKDetectedObjectLabelFood]) {
...
}
// or
if ([object.labels[0].index == MLKDetectedObjectLabelIndexFood]) {
...
}Remove Firebase dependencies
Remove Firebase dependencies after migration. Follow these steps:
- Remove the Firebase configuration file by deleting the
GoogleService-Info.plistfile from your app's directory and your Xcode project. - Remove any Firebase cocoapod, such as
pod 'Firebase/Analytics', from your Podfile. - Remove any FirebaseApp initialization, such as
FirebaseApp.configure()from your code. - Delete your Firebase app at the Firebase console according to the instructions on the Firebase support site.
Getting Help
If you run into any issues, please check out our Community page where we outline the channels available for getting in touch with us.