Page Summary
-
ModelManageris a class in MLKit used to manage machine learning models. -
It provides methods for checking if a model is downloaded, downloading models, and deleting downloaded models.
-
You can get a
ModelManagerinstance through themodelManager()class method. -
To monitor download progress and outcome, listen to
.mlkitModelDownloadDidSucceedand.mlkitModelDownloadDidFailnotifications. -
Use the
isModelDownloaded()function to check if a model is downloaded before using it.
ModelManager
class ModelManager : NSObjectManages models that are used by MLKit features.
-
Returns a
ModelManagerinstance.Declaration
Swift
class func modelManager() -> SelfReturn Value
A
ModelManagerinstance. -
Unavailable. Use the
modelManager()class method. -
Checks whether the given model has been downloaded.
Declaration
Swift
func isModelDownloaded(_ remoteModel: MLKRemoteModel) -> BoolParameters
remoteModelThe 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
.mlkitModelDownloadDidSucceedand.mlkitModelDownloadDidFailnotifications defined inMLKModelDownloadNotifications.h. If the latest model is already downloaded, completes without additional work and posts.mlkitModelDownloadDidSucceednotification, indicating that the model is ready to use.Declaration
Swift
func download(_ remoteModel: MLKRemoteModel, conditions: MLKModelDownloadConditions) -> ProgressParameters
remoteModelThe model to download.
conditionsThe 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, completion: @escaping (Error?) -> Void)Parameters
remoteModelThe downloaded model to delete.
completionHandler to call back on the main queue when the model deletion completed successfully or failed with the given
error.