MLKitCommon Framework Reference
Stay organized with collections
Save and categorize content based on your preferences.
ModelManager
class
ModelManager
:
NSObject
Manages models that are used by MLKit features.
-
Returns a ModelManager
instance.
Declaration
Swift
class
func
modelManager
()
->
Self
Return Value
A ModelManager
instance.
-
-
Checks whether the given model has been downloaded.
Declaration
Swift
func
isModelDownloaded
(
_
remoteModel
:
MLKRemoteModel
)
->
Bool
Parameters
remoteModel
The model to check the download status for.
Return Value
Whether the given model has been downloaded.
-
Downloads the given model from the server to a local directory on the device. Use isModelDownloaded(_:)
to check the download status for the model. If this method is invoked and
the model has already been downloaded, a request is made to check if a newer version of the model
is available for download. If available, the new version of the model is downloaded.
To know when this method is done, observe the .mlkitModelDownloadDidSucceed
and .mlkitModelDownloadDidFail
notifications defined in MLKModelDownloadNotifications.h
.
If the latest model is already downloaded, completes without additional work and posts .mlkitModelDownloadDidSucceed
notification, indicating that the model is ready to use.
Declaration
Swift
func
download
(
_
remoteModel
:
MLKRemoteModel
,
conditions
:
MLKModelDownloadConditions
)
->
Progress
Parameters
remoteModel
|
|
conditions
|
The conditions for downloading the model.
|
Return Value
Progress for downloading the model.
-
Deletes the downloaded model from the device.
Declaration
Swift
func
deleteDownloadedModel
(
_
remoteModel
:
MLKRemoteModel
)
async
throws
Parameters
remoteModel
|
The downloaded model to delete.
|
completion
|
Handler to call back on the main queue when the model deletion completed
successfully or failed with the given error
.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eModelManager\u003c/code\u003e is a class in MLKit used to manage models for ML features, accessible via the \u003ccode\u003emodelManager()\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eIt provides functionalities like checking if a model is downloaded (\u003ccode\u003eisModelDownloaded(_:)\u003c/code\u003e) and downloading models (\u003ccode\u003edownload(_:conditions:)\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eModels can be updated by invoking \u003ccode\u003edownload(_:conditions:)\u003c/code\u003e again, which automatically fetches newer versions if available.\u003c/p\u003e\n"],["\u003cp\u003eDownloaded models can be deleted from the device using the \u003ccode\u003edeleteDownloadedModel(_:)\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eDownload progress and success/failure are communicated via notifications defined in \u003ccode\u003eMLKModelDownloadNotifications.h\u003c/code\u003e.\u003c/p\u003e\n"]]],["The `ModelManager` class manages MLKit models. It provides a singleton instance via `modelManager()`. Core actions include: checking if a model is downloaded using `isModelDownloaded(_:)`; downloading a model with `download(_:conditions:)`, which also checks for newer versions and posts success/failure notifications; and deleting a downloaded model with `deleteDownloadedModel(_:)`. The class also has an initializer, `-init`, but it is unavailable for external use.\n"],null,["# MLKitCommon Framework Reference\n\nModelManager\n============\n\n class ModelManager : NSObject\n\nManages models that are used by MLKit features.\n- `\n ``\n ``\n `\n\n ### [modelManager()](#/c:objc(cs)MLKModelManager(cm)modelManager)\n\n `\n ` \n Returns a `ModelManager` instance. \n\n #### Declaration\n\n Swift \n\n class func modelManager() -\u003e Self\n\n #### Return Value\n\n A `ModelManager` instance.\n- `\n ``\n ``\n `\n\n ### [-init](#/c:objc(cs)MLKModelManager(im)init)\n\n `\n ` \n Unavailable. Use the [modelManager()](../Classes/ModelManager.html#/c:objc(cs)MLKModelManager(cm)modelManager) class method.\n- `\n ``\n ``\n `\n\n ### [isModelDownloaded(_:)](#/c:objc(cs)MLKModelManager(im)isModelDownloaded:)\n\n `\n ` \n Checks whether the given model has been downloaded. \n\n #### Declaration\n\n Swift \n\n func isModelDownloaded(_ remoteModel: MLKRemoteModel) -\u003e Bool\n\n #### Parameters\n\n |---------------------|---------------------------------------------|\n | ` `*remoteModel*` ` | The model to check the download status for. |\n\n #### Return Value\n\n Whether the given model has been downloaded.\n- `\n ``\n ``\n `\n\n ### [download(_:conditions:)](#/c:objc(cs)MLKModelManager(im)downloadModel:conditions:)\n\n `\n ` \n Downloads the given model from the server to a local directory on the device. Use\n [isModelDownloaded(_:)](../Classes/ModelManager.html#/c:objc(cs)MLKModelManager(im)isModelDownloaded:) to check the download status for the model. If this method is invoked and\n the model has already been downloaded, a request is made to check if a newer version of the model\n is available for download. If available, the new version of the model is downloaded.\n\n To know when this method is done, observe the [.mlkitModelDownloadDidSucceed](../Constants.html#/c:@MLKModelDownloadDidSucceedNotification) and\n [.mlkitModelDownloadDidFail](../Constants.html#/c:@MLKModelDownloadDidFailNotification) notifications defined in `MLKModelDownloadNotifications.h`.\n If the latest model is already downloaded, completes without additional work and posts\n [.mlkitModelDownloadDidSucceed](../Constants.html#/c:@MLKModelDownloadDidSucceedNotification) notification, indicating that the model is ready to use. \n\n #### Declaration\n\n Swift \n\n func download(_ remoteModel: MLKRemoteModel, conditions: MLKModelDownloadConditions) -\u003e Progress\n\n #### Parameters\n\n |---------------------|-------------------------------------------|\n | ` `*remoteModel*` ` | The model to download. |\n | ` `*conditions*` ` | The conditions for downloading the model. |\n\n #### Return Value\n\n Progress for downloading the model.\n- `\n ``\n ``\n `\n\n ### [deleteDownloadedModel(_:)](#/c:objc(cs)MLKModelManager(im)deleteDownloadedModel:completion:)\n\n `\n ` \n Deletes the downloaded model from the device. \n\n #### Declaration\n\n Swift \n\n func deleteDownloadedModel(_ remoteModel: MLKRemoteModel) async throws\n\n #### Parameters\n\n |---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n | ` `*remoteModel*` ` | The downloaded model to delete. |\n | ` `*completion*` ` | Handler to call back on the main queue when the model deletion completed successfully or failed with the given [error](../Constants.html#/c:@MLKModelDownloadUserInfoKeyError). |"]]