ModelManager

class ModelManager : NSObject

Manages models that are used by MLKit features.

  • Returns the ModelManager instance for the default Firebase app. The default Firebase app instance must be configured before calling this method; otherwise, raises FIRAppNotConfigured exception. Models hosted in non-default Firebase apps are currently not supported. The returned model manager is thread safe.

    Declaration

    Swift

    class func modelManager() -> Self

    Return Value

    The ModelManager instance for the default Firebase app.

  • Unavailable. Use the modelManager() class method.

  • Registers a remote model. The model name is unique to each remote model and can only be registered once with a given instance of ModelManager. The model name should be the same name used when the model was uploaded to the Firebase Console. It’s OK to separately register a remote and local model with the same name for a given instance of ModelManager.

    Declaration

    Swift

    func register(_ remoteModel: FIRRemoteModel) -> Bool

    Parameters

    remoteModel

    The remote model to register.

    Return Value

    Whether the registration was successful. Returns NO if the given remoteModel is invalid or has already been registered.

  • Registers a local model. The model name is unique to each local model and can only be registered once with a given instance of ModelManager. It’s OK to separately register a remote and local model with the same name for a given instance of ModelManager.

    Declaration

    Swift

    func register(_ localModel: FIRLocalModel) -> Bool

    Parameters

    localModel

    The local model to register.

    Return Value

    Whether the registration was successful. Returns NO if the given localModel is invalid or has already been registered.

  • Returns the registered remote model with the given name. Returns nil if the model was never registered with this model manager.

    Declaration

    Swift

    func remoteModel(withName name: String) -> FIRRemoteModel?

    Parameters

    name

    Name of the remote model.

    Return Value

    The remote model that was registered with the given name. Returns nil if the model was never registered with this model manager.

  • Returns the registered local model with the given name. Returns nil if the model was never registered with this model manager.

    Declaration

    Swift

    func localModel(withName name: String) -> FIRLocalModel?

    Parameters

    name

    Name of the local model.

    Return Value

    The local model that was registered with the given name. Returns nil if the model was never registered with this model manager.

  • Checks whether the given remote model has been downloaded.

    If the given remote model has not been registered yet, then this method returns NO.

    Declaration

    Swift

    func isRemoteModelDownloaded(_ remoteModel: FIRRemoteModel) -> Bool

    Parameters

    remoteModel

    The remote model to check the download status for.

    Return Value

    Whether the given model has been downloaded.

  • Downloads the given remote model from the server to a local directory on the device, if the model hasn’t already been downloaded. Use isRemoteModelDownloaded(_:) to check the download status for the remote model.

    To be notified when a model download request completes, observe the ‘.firebaseMLModelDownloadDidSucceedand.firebaseMLModelDownloadDidFailnotifications defined inFIRModelDownloadNotifications.h. If the given remote model has not been registered yet, then this method returns completed progress and posts a .firebaseMLModelDownloadDidFail` notification. The download conditions provided at the time the model was registered will be used for this download request.

    Declaration

    Swift

    func download(_ remoteModel: FIRRemoteModel) -> Progress

    Parameters

    remoteModel

    The remote model to download.

    Return Value

    Progress for downloading the model.