AI-generated Key Takeaways
-
MLKModelManager is a class that manages models used by MLKit features, providing functionalities such as downloading, checking download status, and deleting downloaded models.
-
It offers a singleton instance accessed through the
modelManager()class method, and direct initialization is unavailable. -
You can check if a model is downloaded using
isModelDownloaded:, download a model usingdownloadModel:conditions:, and delete a downloaded model usingdeleteDownloadedModel:completion:. -
The
downloadedEntityExtractionModelsproperty provides a set of already-downloaded entity extraction models, which can be managed for disk space. -
Model download progress and completion are communicated through notifications defined in
MLKModelDownloadNotifications.h.
MLKModelManager
@interface MLKModelManager : NSObjectManages models that are used by MLKit features.
-
Returns a
ModelManagerinstance.Declaration
Objective-C
+ (nonnull instancetype)modelManager;Return Value
A
ModelManagerinstance. -
Unavailable. Use the
modelManager()class method.Declaration
Objective-C
- (nonnull instancetype)init; -
Checks whether the given model has been downloaded.
Declaration
Objective-C
- (BOOL)isModelDownloaded:(nonnull MLKRemoteModel *)remoteModel;Parameters
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
Objective-C
- (nonnull NSProgress *)downloadModel:(nonnull MLKRemoteModel *)remoteModel conditions: (nonnull MLKModelDownloadConditions *)conditions;Parameters
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
Objective-C
- (void)deleteDownloadedModel:(nonnull MLKRemoteModel *)remoteModel completion:(nonnull void (^)(NSError *_Nullable))completion;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.
-
A set of already-downloaded entity extraction models. These models can be then deleted through
ModelManager‘sdeleteDownloadedModel(_:completion:)API to manage disk space.Declaration
Objective-C
@property (nonatomic, readonly) NSSet<MLKEntityExtractionRemoteModel *> *_Nonnull downloadedEntityExtractionModels;