MLKitCommon Framework Reference

  • ModelManager is a class in MLKit used to manage models for ML features, accessible via the modelManager() method.

  • It provides functionalities like checking if a model is downloaded ( isModelDownloaded(_:) ) and downloading models ( download(_:conditions:) ).

  • Models can be updated by invoking download(_:conditions:) again, which automatically fetches newer versions if available.

  • Downloaded models can be deleted from the device using the deleteDownloadedModel(_:) method.

  • Download progress and success/failure are communicated via notifications defined in MLKModelDownloadNotifications.h .

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.

  • Unavailable. Use the modelManager() class method.

  • 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

    The model to download.

    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 .

Design a Mobile Site
View Site in Mobile | Classic
Share by: